Hi im trying to get a uniform random number generator using a crypto algorithm as the engine . DES is possible to be used but in this case i have used TEA according to this http://myweb.tiscali.co.uk/jgrimbleby/random.htm porting the code from c++ to python.The problem im having is i need the range to be between 0 and 1 .currently the values im getting are very large 10^76 range.Any idea if its a transcription error on my part or if theres any addition i can put in to get the desired range.
class psrTEA:
def __init__(self):
self.m = 4294967296.0
self.d = 0X09E3779B9L
self.k0 = 0X0C7D7A8B4L
self.k1 = 0X09ABFB3B6L
self.k2 = 0X073DC1683L
self.k3 = 0X017B7BE73L
self.y = 123456789L
self.z = 987654321L
def rnd(self):
s = 0
self.y = long(time.time())
self.z = long(time.clock())
for n in range(31):
s += self.d
self.y += (self.z << 4) + self.k0 ^ self.z + s ^ (self.z >> 5) + self.k1
self.z += (self.y << 4) + self.k2 ^ self.y + s ^ (self.y >> 5) + self.k3
return ((self.z + self.y / self.m)/ self.m)
Compute your highest value (or compute lots of values, take the max, maybe guess a little bit based on a power of 2 or something).
Then divide each of your large results by a float version of the highest value. That should scale things to 0..1.