rubycon / isaac.js

A JavaScript implementation of the ISAAC PRNG
50 stars 17 forks source link

How to get positive random integers #1

Closed amper5and closed 11 years ago

amper5and commented 11 years ago

Are the random numbers uniformly distributed on both sides of zero when using isaac.rand()? In the README, you state

isaac.rand() allow you to get a random 32-bit integer between -2147483648 (0x00000000) and 2147483647 (0xFFFFFFFF).

If I add 2147483648 to the output, would the result be evenly distributed between 0 and 4294967296?

rubycon commented 11 years ago

Yes. The output is evenly distributed between 0x00000000 and 0xFFFFFFFF, which is intepreted as integers between -2147483648 and 2147483647 in javascript. If you add 2147483648 to the output you will have an evenly distributed result between 0 and 4294967295.