Jump to content

poisson random numbers


PC Nerd

Recommended Posts

Hi,

 

Im looking for a way to generate random numbers..... well that arent really random.  ie - if i was to pass the function the number 5 & 10, it would generate random numbers in the rand og 5+- 10, that are closer to 5.

 

Ive looked around on google, and found very little regarding this problem.  my understanding is that im looking for somethign using poisson's probability formula in statistics.... but thats as much as i can figure out.

 

any ideas?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/120517-poisson-random-numbers/
Share on other sites

You could consider creating a system using "real" random numbers (pseudo-random really, but I need to use the term to distinguish from the "random numbers" you want) in which, as the resulting number varies more from the desired number, you could have a further increasing chance to "reroll" the number in a smaller range slightly closer to the number. True, this isn't an ideal implementation, but it might be something you want to consider as it could potentially give you more control of the means than a third party generator would... if implemented correctly of course.

ive found this:

 

math.exp(-lamb)*pow(lamb,x)/factorial(x)

 

thats in python, buti also found somethign else in python that incorperates a random float(0-1)... so ill play around with that.  its only problem is that its actual average is usually a bit less than lamba..... so ill have to tweak it a bit..

 

 

thanks

ok - ive found my solution.....

def poisson(lam):
    random.seed(5)
    L = math.e**-lam
    k = 0
    p = 1
    while True:
        k += 1
        p *= random.random()
        if p < L:
            break
    return k-1

 

 

now i know thats in python - but im in the middle of converting it to php,, using constants M_E etc.

 

ive run a few tests in python and that function what im looking for.

 

Thanks for the help - if you want me to post my finished code here just yell.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.