Random number generator (included): Difference between revisions
Content added Content deleted
(Add C) |
m (→{{header|C}}) |
||
Line 14: | Line 14: | ||
There are no requirements as to the algorithm to be used for generating the random numbers. The standard specifies the interface, and how the rand() function reacts in a multithreaded environment. The rand() function will return an integer in the range 0-RAND_MAX. RAND_MAX must be at least 32767. The returned integers are to be uniformly distributed in this interval.[[http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf]] |
There are no requirements as to the algorithm to be used for generating the random numbers. The standard specifies the interface, and how the rand() function reacts in a multithreaded environment. The rand() function will return an integer in the range 0-RAND_MAX. RAND_MAX must be at least 32767. The returned integers are to be uniformly distributed in this interval.[[http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf]] |
||
The libraries of popular C versions implement the rand() function with a linear congruential generator. The specific multiplier and constant varies by implementation, as does which subset of bits within the result is returned as the random number. |
The libraries of many popular C versions implement the rand() function with a linear congruential generator. The specific multiplier and constant varies by implementation, as does which subset of bits within the result is returned as the random number. |
||
As mentioned above, linear congruential generators have problems in their 'randomness' and should not be used where a good quality random number generator is required. |
As mentioned above, linear congruential generators have problems in their 'randomness' and should not be used where a good quality random number generator is required. |