Re: How to generate random 32bit integers
- Posted by DerekParnell (admin) Feb 17, 2011
- 1798 views
cp said...
I have a need to generate random numbers in a range of 1 to n. N varies but may be as high as max 32 bit Uint.. 4,294,967,295.
I looks like I can do this with v 4.0 but unfortunately my app is in 3.1 and I'm not able to convert and test in the short term.
Speed is more important than distribution. It looks like the windows api may have a call for getting random numbers however there may be something better (easier/faster) coded in euphoria?
Thanks
Try ...
function rand32() atom A,B A = rand(#10000) - 1 B = rand(#10000) - 1 return (A * #10000 + B) -- Returns an ATOM not an INTEGER, in the range 0 to #FFFFFFFF end function