Last active
October 10, 2016 20:20
-
-
Save nikoloza/7772b1324fe254de6eab77da8ec722e7 to your computer and use it in GitHub Desktop.
I've heard Math.random() is based on timestamp. I wanted to check how we can predict it with maximum accuracy. So if that two numbers are close together (can be the same in multithreads maybe), we can definitely check and hack any system based on Math.random().
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(interval){ | |
const start = Date.now() | |
const end = start + 1000 | |
let i = 0 | |
function hackRandom () { | |
let now = Date.now() | |
if (now > end) { | |
console.log(`timestamp: ${now}`, `random: ${Math.random()}`) | |
i++ | |
} | |
if (i > 1) { | |
clearInterval(a) | |
clearInterval(b) | |
} | |
} | |
var a = setInterval(hackRandom, interval) | |
var b = setInterval(hackRandom, interval) | |
})(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment