Fixed a few issues with random number generation.