Add random number generator to ThreadContext.

Make rand_n and rand_I use it, and add srand that sets its seed.