import random def simulate_sadge_rng(simulations, throws=4, breaks=3): """Simulates the probability of a certain number of eyes breaking for a given number of throws.""" simulation_tick = simulations / 10 probability_of_eye_breaking = 1/5. bad_rng = 0. for simulation in range(simulations+1): if simulation % simulation_tick == 0: print('{:.0f}% Complete...'.format(100.*simulation/simulations)) eyes_broken = 0 for throw in range(throws): if random.random() <= probability_of_eye_breaking: eyes_broken += 1 if eyes_broken >= breaks: bad_rng += 1 probability = bad_rng / simulations print('Bad RNG Probability: ~{:.2f}%'.format(probability*100)) ### You can change the number of simulations here ### ### The higher it is, the more accurate it will be ### simulate_sadge_rng(100000)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question