samedi 6 février 2016

Python - How to generate a random number with a bitwise probability?

I need to work out the number of atoms decayed in a specified time. I was given the half life of Radon-222 and have calculated from this the probability that any one atom will decay within 1 minute.

If I have x atoms and the probability is y, how do I calculate the number which decay within 1 minute?

I have a very inefficient function at the moment (see below) but this can probably be done much more easily.

def Decay(atomno, decayrate):
out = 0
for atom in range(atomno):
    if random.uniform(0,1)<decayrate:
        out += 1
return out




Aucun commentaire:

Enregistrer un commentaire