3 ms·
Can it be used as a good source of random numbers or is the noise not truly “white”?
by gumby 3y ago
Can it be used as a good source of random numbers or is the noise not truly “white”?
- sethhochberg 3y agoUnder the hood it’s just making calls to Math.random(), so the white noise generated is exactly as reliable a source of randomness as the system as the system could give you directly.
- travisjungroth 3y agoIt’s at at most as good of a source but almost certainly worse. Lots of entropy dropped and biases introduced.
- sethhochberg 3y agoVery fair point. Transforming the randomness to fit it into the audible spectrum would certainly have side effects
- yura 3y ago>as reliable a source of randomness as the system as the system could give you directly Not sure what you mean by this. Which system?
- gumby 3y agoI thought that was the point GP’s comment is making, but a reply to a parallel comment to yours suggests otherwise.
- fragmede 3y agoThe combination of the operating system (Linux/MacOS/Windows) and the particular hardware it has access to. With different hardware, /dev/(u)random has different qualities of entropy.
- masklinn 3y agoJS’s Math.random is not a system (or CS) RNG, and a few years back it was barely an RNG at all: https://medium.com/@betable/tifu-by-using-math-random-f1c308c4fd9d# https://medium.com/@betable/tifu-by-using-math-random-f1c308... So no, Math.random is very much not > as reliable a source of randomness as the system
- adgjlsfhk1 3y agothat's horrifying. I do slightly disagree with the final thoughts and works say that one of the xoshiro 256 generators is probably better than the 1024 ones. 256 bits of state is plenty to give you a longer cycle length than you will ever need (even considering birthday paradox) and the reduced state means it fits in a single cache line
- masklinn 3y agoAfter the linked article as well as https://jandemooij.nl/blog/math-random-and-32-bit-precision/ https://jandemooij.nl/blog/math-random-and-32-bit-precision/ which follows from it, the main three browsers (Chrome[0], Firefox[1], Safari[2]) actually switched to Xorshift128+. So these days Math.random is nowhere near as horrifying as it was back then, however it's still not a system or a userland CSPRNG, for that you need `crypto.getRandomValues()` (https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getR...). [0] https://v8.dev/blog/math-random https://v8.dev/blog/math-random [1] https://bugzilla.mozilla.org/show_bug.cgi?id=322529#c99 https://bugzilla.mozilla.org/show_bug.cgi?id=322529#c99 [2] https://bugs.webkit.org/show_bug.cgi?id=151641 https://bugs.webkit.org/show_bug.cgi?id=151641
- moritzwarhier 3y agoMath.random() is a pragmatic PRNG with no strong guarantees and implementations vary. Focus on speed. OS can give more entropy if that's what matters https://v8.dev/blog/math-random https://v8.dev/blog/math-random
- messe 3y agoI've seen visual demonstrations of PRNG bias before, but are the biases of typical implementations of Math.random "above the noise threshold" (pun intended) where humans could distinguish them from truly random streams of audio?
- moritzwarhier 3y agoI don't think so, no. The way I understood op was to use the generated audio itself as a source of entropy, which would be a bad idea if not using a CSPRNG perfectly tuned to the sampling rate and lossless audio I think :) but I'm just guessing there regarding the effects of quality.
- amenghra 3y agoIt calls Math.random() which is NOT truly random. crypto.getRandomValues() is what you would use if you wanted truly random noise.
- tiffanyg 3y agoOh. I just sample from my own brain if I want truly random noise. Ba-dum-tisss...
- TeMPOraL 3y agoSo the question now is, if it were calling `crypto.getRandomValues()` instead, would it sound different? EDIT: This is not a 100% joke question. I'd expect both versions to sound the same, but at the same time, there's a threshold on the RNG spectrum between "getRandomNumber() { return 4; }" and some truly random quantum source, where if you feed the RNG to audio output, people will be able to distinguish between "bad RNGs" (left of threshold), and "good RNGs" (right of threshold). I wonder where that threshold falls.
- pravus 3y ago> would it sound different? I don't believe it would. While there can be pretty bad PRNGs, they are typically implemented to produce a particular statistical distribution which would be identical to a real random source for the purposes of white noise. This is due to the fact that audio is a superposition of frequencies which takes time and multiple samples to cohere. PRNGs can be bad for things like crypto because each individual generated value has significant implications for the entire set of operations.
- esnard 3y agoIt wouldn't sound different, even if you have absolute pitch, whatever the "speed" of the random sounds would be. Both algorithms will generate sufficiently random values from a human perspective. Unless you carefully look into them, with a very specific mathematics / crypto knowledge, you wouldn't even be able to tell which one is pseudo-random, and which one is random: and if you somehow are able to, then it would just mean that the underlying RNG is very, very bad.
- toomim 3y agoGood point. You're much better off playing a podcast of white noise, which repeats the exact same sequence of bits each time you hit play.