JavaScript
That was fun!
arr = []
index = 0
function init(seed) {
index = 0
arr[0] = seed
for (var i = 1; i < 624; i ++) {
arr[i] = (1812433253 * (arr[i-1] ^ (arr[i-1] >>> 30)) + i) | 0
}
}
function getNumber() {
if (index == 0) generateNumbers()
var y = arr[index]
y ^= (y >>> 11)
y ^= ((y << 7) & 2636928640)
y ^= ((y << 15) & 4022730752)
y ^= (y >>> 18)
index = (index + 1) % 624
return y
}
function generateNumbers() {
for (var i = 0; i < 624; i ++) {
var y = (arr[i] & 0x80000000) + (arr[(i+1) % 624] & 0x7fffffff)
arr[i] = arr[(i + 397) % 624] ^ (y >>> 1)
if (y % 2 != 0) arr[i] ^= 2567483615
}
}
// let's get our seed now from the SE API
var x = new XMLHttpRequest()
x.open('GET', 'http://api.stackexchange.com/2.2/answers?pagesize=10&order=desc&sort=activity&site=stackoverflow&filter=!Sri2UzKb5mTfr.XgjE', false)
x.send(null)
// we've got the answer data, now just add up all the numbers.
// only 4 digits at a time to prevent too big of a number.
var seed = 0
var numbers = x.responseText.match(/\d{0,4}/g)
for (var i = 0; i < numbers.length; i++) seed += +numbers[i]
init(seed)
for (var i = 0; i < 10; i++) console.log(getNumber())
I wrote up the Mersenne Twister in JS. Then, I realized I had to get a seed from somewhere.
So, I decided I would get it from the Stack Exchange API! (I could use localStorage
and increment a counter, but that's no fun.) So, I grabbed the 10 most recently active answers, and then I just took every 4 or less consecutive digits in the response and added them up.
These seeds are always different, since Stack Overflow is constantly updating (and my quota keeps going down!) The numbers include answer IDs, question IDs, scores, up/downvote counts, owner rep/IDs, and the wrapper data (quota and such). On one run I got 256845
, then 270495
, and then 256048
, etc....
This logs 10 random 32-bit two's-complement numbers to the console. Sample output:
247701962
-601555287
1363363842
-1184801866
1761791937
-163544156
2021774189
2140443959
1764173996
-1176627822