Last active
November 15, 2020 13:07
-
-
Save torralbaa/99f3e9798490741115771bfa235368fa to your computer and use it in GitHub Desktop.
Dice in JavaScript with an (aprox.) 49.7%-50.3% distribution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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