# What's wrong with this RNG function?

from time import time

def baseRandom():
return hash(str(time()))

def randFromZero(maximum):
return baseRandom() % maximum

def randRange(minimum, maximum):
return randFromZero(maximum - minimum) + minimum


I ask what's wrong because it seems so simple and stupid. This is something I just thought up one day and put together in 5 minutes, but it seems to generate even and unpredictable results. I've done a couple of simple tests like generating a lot of numbers and looking at the variance between the amount of times each number is generated, and using it to create a little grid which has tiles that are either black or white with equal probability, in which I saw no clear patterns. Hopefully someone who knows a thing or two about this can educate me.

-
How are you intending to use the "random" output? Why aren't you using the builtin random functions? –  JeffS Apr 25 at 19:24
@JeffS I'm not intending to use it and always use the built-in functions. This is just a bit of fun. –  user1149589 Apr 25 at 19:35
The time() function returns quantized time; the least significant digits of the time are "chunky" and usually represent a small subset of available numbers. Hashing the string will introduce more clumpiness; ASCII strings tend to be very sparse, and you are taking the string of a number. The hash function will map to a very small portion of the integer space. Now, the modulus of a small portion of the integer space is an even smaller portion. –  Bob Dalgleish Apr 25 at 19:50