2 ms·
This one doesn't really "beat" this, but here is a simple PRNG that you can trivially compute using mental arithmetics proposed by George Marsaglia [1]: 1. Sel
by camel-cdr 4y ago
This one doesn't really "beat" this, but here is a simple PRNG that you can trivially compute using mental arithmetics proposed by George Marsaglia [1]:
1. Select an initial random number (seed) between 1 and 58.
(This is accomplished by mentally collecting entropy from the environment, e.g. counting a group of objects you don't knew the count of before)
2. Multiply the least significant digit by 6, add the most significant digit to the result, and use the new result as the next seed/state.
3. The second digit of the state is your generated pseudorandom number.
4. Goto 2.
Sequence generated by 42:
42 -> 2*6+4=16 -> 6*6+1=37 -> ...
42|16|37|45|34|27|44|28|50|05|03|18|49|58|53|23|20|02|12|13|19|55|35|33|21
2| 6| 7| 5| 4| 7| 4| 8| 0| 5| 3| 8| 9| 8| 3| 3| 0| 2| 2| 3| 9| 5| 5| 3| 1
[1] "Multiply with carry", George Marsaglia (1994): https://groups.google.com/g/sci.math/c/6BIYd0cafQo/m/Ucipn_5T_TMJ https://groups.google.com/g/sci.math/c/6BIYd0cafQo/m/Ucipn_5...
Edit: Thanks to lifthrasiir you can try it out your self:
(async () => {
let x = 42;
for (let i = 0; i < 10; ++i) {
for (let j = 0; j < 10; ++j) {
x = (x / 10) + (x % 10) * 6;
(x & 1 ? captureBtnLeftFunc : captureBtnRightFunc)({ preventDefault() {} });
}
await new Promise(r => requestAnimationFrame(r));
}
})()
Edit2: fixed *'s
- defrost 4y agoAhh, George Marsaglia was one of the great OG's of random .. For any that like such things and haven't yet seen them, his Ziggurat algorithm family for generating target random distributions dates back to the 60's and was written up ~ 2000; the classic is the ZA for a random binomial distribution. Good approach for the bulk rapid generation of large amounts of distributed random values. [7] https://www.jstatsoft.org/article/view/v005i08 https://www.jstatsoft.org/article/view/v005i08 [2] https://en.wikipedia.org/wiki/Ziggurat_algorithm https://en.wikipedia.org/wiki/Ziggurat_algorithm
- silvestrov 4y agoYou need to escape the * in the formula or indent it as code: 42 -> 2*6+4=16 -> 6*6+1=37 -> ...