Possible Duplicate:
How should I test randomness?
One of the features to be developed in our application was allowing user to click a button which will choose an element at random out of (normally 5-10) values registered in the database. The randomness doesn’t need to be secure or scientifically uniform, but we do need it to be somehow unpredictable and not noticeably biased to one of the value.
Any suggestion how to write a good unit test and functional test for this feature?
3
You can use the same seed on 2 parallell processes, and if they start in the same general (in GHz processor terms) timeframe they will have the same exact seed to the static seed. Or most languages if seeded with the same static seed will have the same numerical generation (Java’s a good RNG example of this API style).
To combat the inherent static predictability of this, RNG’s are usually seeded with the internal system time down to micro or nano second range, giving high unpredictability in the long run and near impossible ability to predict based on time in the short, since it’s internal crystal clock cycles that feed up to the API.
As an aside: all numbers generated by machines will be pseudo-random, but close enough for government work.
To get a numerical range you want just take the integer modulo (integer_range_max) of the RNG value [0-1). So RNG * Modulo % Modulo will give you the range.