Re: 32-bit random numbers
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jul 03, 2004
- 590 views
Tommy Carlier wrote: > How to create a 32-bit random integer between 1 and n (n = 32-bit integer > atom): > > function rand32(atom n) > if n <= #3FFFFFFF then return rand(n) > else return rand(n - #3FFFFFFF) + rand(#3FFFFFFF) - 1 end if -- > end function > > PS: if you leave out the -1 at the end, the number 1 will never be chosen. Hi, this function can not take a big 32-bit integer atom as argument. If n > 2*#3FFFFFFF, then (n - #3FFFFFFF) > #3FFFFFFF, that means the argument to the first call of rand() will be too big, and Euphoria aborts with a syntax error. Also, I want the rand32() function to behave like Euphoria's built-in rand() function. That means, the returned values must have a uniform distribution. Are you sure, that the sum rand(n - #3FFFFFFF) + rand(#3FFFFFFF) is uniformly distributed? Sorry, I don't have a statistical test for this at hand ATM. Regards, Juergen