Fix a bug with random number generator, improve random number generation.
Fix bug in random methods and improved random calls.