Re: 32-bit random numbers
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 03, 2004
- 579 views
Juergen Luethje wrote: > > Hi all, > > for Euphoria's function rand(x), x may only be from 1 to the largest > positive value of type integer (#3FFFFFFF). > > I would like to have a function, that can take any unsigned 32-bit integer > -- i.e. in the interval [0,#FFFFFFFF] -- as argument. Any ideas? You could try something like this... object vOldSeed vOldSeed = #69F5C10D function rand32() vOldSeed = vOldSeed * date() vOldSeed = vOldSeed[1] + vOldSeed[2] + vOldSeed[3] + vOldSeed[4] + vOldSeed[5] + vOldSeed[6] vOldSeed += time() * (time() + 17) vOldSeed = floor(remainder(vOldSeed * (vOldSeed - 3), #3FFFFFFF)) set_rand(vOldSeed) return and_bits(rand(#3FFFFFFF), #FFFF) * #10000 + and_bits(rand(#3FFFFFFF), #FFFF) end function -- Derek Parnell Melbourne, Australia