2 ms·
For the curious, xorshift128+: uint64_t a = s[0]; uint64_t b = s[1]; s[0] = b; a ^= a << 23; a ^= a >> 18; a ^= b; a ^= b >> 5; s[1] = a;
by wruza 2y ago
For the curious, xorshift128+:
uint64_t a = s[0];
uint64_t b = s[1];
s[0] = b;
a ^= a << 23;
a ^= a >> 18;
a ^= b;
a ^= b >> 5;
s[1] = a;
return a + b;
https://stackoverflow.com/a/34432126 https://stackoverflow.com/a/34432126
- Retr0id 2y agoFun fact, the state update function can be modelled as the multiplication of the state vector by a constant matrix (where the vector/matrix elements are all in GF(2)). By raising that matrix to a power n, you can use the resultant matrix to compute n state updates at once, allowing you to "skip ahead" arbitrarily into the output stream. Hypothetically, you could use this to vectorize/parallelize computation of xorshift128+ output sequences in large batches, but I'm not sure anyone's ever bothered to do this because the naive sequential method is so cheap.
- deleted 2y ago[deleted]
- shiftingleft 2y agoThe easiest way to parallelize this RNG is to just run it in parallel on multiple states.
- 8n4vidtmkvmk 2y agoI could see some speedrunners wanting to do this. I think it was in Windwaker some speedrunners ran some statistical analysis so they could beat this one mini-game where the odds were stacked against you.