PC Nerd Posted August 20, 2008 Share Posted August 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 20, 2008 Share Posted August 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted August 20, 2008 Author Share Posted August 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted August 21, 2008 Share Posted August 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted August 21, 2008 Author Share Posted August 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 25, 2008 Share Posted August 25, 2008 Poisson means fish in French. So basically you wanted like biased random numbers, right? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted August 26, 2008 Author Share Posted August 26, 2008 yeah - I got it working in python ( not perfectly)... but working enough for me to play with....... If anyone wants the pytohn code ill post it here if you want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.