3 ms·
I am not really sure what is best and I am mostly interested in PRNGs for gaming anyways (which might optimise for performance over randomness, perhaps?), but w
by wsc981 5y ago
I am not really sure what is best and I am mostly interested in PRNGs for gaming anyways (which might optimise for performance over randomness, perhaps?), but with that said ...
I recently came across this discussion on RNG algorithms in JavaScript. Perhaps this short article has some good suggestions on algorithms that improve over Mersenne Twister: https://github.com/nquinlan/better-random-numbers-for-javascript-mirror https://github.com/nquinlan/better-random-numbers-for-javasc...
- olliej 5y agoThe core RNGs of the three main JS engines are I believe at this point all Xorshift variants (same core structure, slightly different code interfaces). They also seed (or should seed, I know JSC does) per-global object from a CSRNG. If you have an application that really does need secure random the Dom specifies crypto.getRandomValues, which is specified as requiring a cryptographically secure implementation.
- ajuc 5y agoMy master's thesis was about PRNGs in gaming, mostly about applications but I also did comparison of performance of several generators. Linear Congruential was the fastest of the ones I've tried. ~27 vs ~25 FPS over more complicated generators in a simple 2d arcade game where everything was randomly generated on the fly to showcase how you can use PRNGs in games. I don't remember if I tested xorshift or some other LFSR, it was back in 2009. The results were highly dependent on how many times you use the generator without changing the seed, and I think most games will have similar distribution (over 50% of the time you use the same seed less than 100 times without changing) or even more skewed. Thesis is in Polish so probably won't be of much use, but if anybody's interested: https://easyupload.io/ub59ej https://easyupload.io/ub59ej