Re: 32-bit random numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 function

PS: if you leave out the -1 at the end, the number 1 will never be chosen.

--
tommy online: http://users.pandora.be/tommycarlier
Euphoria Message Board: http://uboard.proboards32.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu