Fixes errors in random number generation

Removed bugs identified in testing