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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

You could just use a simple probability thingy...

 

Example:

 

$rand = rand(1,10);
$number = ($rand  <  ? 1 : 0; 

 

There would [theoretically] be a 70% chance that the number would be 1.

 

 

You could essentially apply the same concept to multiple numbers.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.