I am using Monte Carlo simulations to simulate a preservation system. I have devices in my simulation with certain fail rate. Lets say the fail rate is 1/100000 meaning 1 out of 100000 devices fail each year. If the device fail I pay for the replacement. But I don't get how to catch the device failure randomly in the simulation. As I understand I need to use probability distribution to simulate this behavior. But I do not get how to do it.
Functions in random package seem to provide random number in a particular range which I do not have. Also I do not know what sort of distribution this is.
I hope the question makes sense to people. Any help will be appreciated.
Update on this:
I did this
#/usr/bin/python
import random
def main():
count =0
#fail rate is 1% of 100000, I need to do this probabilistically
for _ in range(1,100000):
x=random.random()
if x <= 1.0/100000:
count += 1
print "x = "+str(x)+" fail device"
print "device failed "+str(count)+" times"
if __name__ == '__main__':
main()
and I get output like
x = 0.000743343826396 fail device
device failed 1 times
[Finished in 0.0s]
Thanks to timgeb for the help! However, I wonder if this behavior is the same as considering a fail rate of 1/100000?
if random.random() < 1.0/100000: device.fail()
? – timgeb