Skip to content

Instantly share code, notes, and snippets.

@torralbaa
Last active November 15, 2020 13:07
Show Gist options
  • Save torralbaa/99f3e9798490741115771bfa235368fa to your computer and use it in GitHub Desktop.
Save torralbaa/99f3e9798490741115771bfa235368fa to your computer and use it in GitHub Desktop.
Dice in JavaScript with an (aprox.) 49.7%-50.3% distribution.
function dice()
{
var seed = Date.now() * 11 ^ ~31;
var a = seed << 8;
var b = seed << 16;
var c = seed << 32;
var d = seed << 64;
a = a ^ b;
b = b ^ c;
c = c ^ d;
d = d ^ a;
return Math.abs((a | d << 11 | c | b >> 21) % 2);
}
try
{
module.exports = dice;
} catch
{
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment