[prev] 109 [next]

Sidetrack: Random Numbers (cont)

  • Two functions are required:

    srand(unsigned int seed) // sets its argument as the seed
    

    rand() // uses a LCG technique to generate random 
           // numbers in the range 0 .. RAND_MAX 
    

    where the constant RAND_MAX is defined in stdlib.h
    (depends on the computer: on the CSE network, RAND_MAX = 2147483647)

  • The period length of this random number generator is very large
    approximately 16 · ((231) - 1)