Here's some code and analysis related to random numbers.
Here are some random facts about pseudorandom number generation.
Proof: the probability of a cycle of length 1 is 1/S. Of length 2 is ((S-1)/S)(1/(S-1))=(1/S). And so on. The sum of i/S for i in 1..S is S(S+1)/2, and the average is (S+1)/2.
Here are some other random number generator related pages.