Friday, October 22, 2010

Randomness Problems

learned alot about php's randomness today. PHP on windows biased on a specific number on specific range. For example this afternoon between 1-47, 24 is favored. Tonight as I post this, it favors 21.

While around 5:00(I believe time has something to do with random number generation) of this afternoon Unix hates 30. It gives this number, no matter how many the choices are, 2/3 of the normal chance.

I generated random integer from 1 to 1000, 1 million times(not exaggerating here), the normal answer should be 10,000 (1M/1K) but 30 is getting just around 6,000 after alot of reset and retries

But tonight as I post this, no bias occurs. It could be that I've just encountered a rare occurrence of a random number generation bug.

What to use when you don't trust php's rand() commands? the mt_rand() function. My boss told me about it just now and I think I'll be using it from now cause it shows no bias when I tested it.

Also, shuffle shuffle() works better than array_rand() when dealing with picking a random item from an array. I used this and get only 0.04% error

Or you can use this function(haha)

I'm a big fan of destiny so it's ironic how I seek the the perfection of randomness XD

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home