@grainloom @jk There's a standard library function for this.
http://www.cs.yale.edu/homes/aspnes/pinewiki/C(2f)Randomization.html#The_rand_function_from_the_standard_library