If you want cryptographic-quality random numbers, both Java and Javascript have them. Math.random() is simply a super-fast decent RNG.<p>Example:<p><pre><code> var buf = new Uint32Array(10);
window.crypto.getRandomValues(buf);
console.log(buf);
</code></pre>
Outputs things like:<p><pre><code> [4027145128, 258543382, 1205615760, 2665675208, 4033127244,
2280027866, 3983484449, 510932333, 1911490534, 2609399642]
</code></pre>
This works in Chrome and FF.<p>IE11 has Crypto.getRandomValues(...)<p>Java has SecureRandom:<p><a href="http://docs.oracle.com/javase/6/docs/api/java/security/SecureRandom.html" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/security/Secur...</a>
That is a nice not-so-subtle reminder. When a PRNG says it is insecure, <i>it is insecure</i>. When a PRNG says it is secure, it <i>might</i> be - get someone very clever to check it first.
nitpick, Firefox doesn't use Rhino, it uses SpiderMonkey which is C++.<p><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey" rel="nofollow">https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Sp...</a>
Math.random() should be used only for tests. That's it.
Performance sucks as it's shared. ThreadLocalRandom is a lot better if you need fast but not-quality random.<p>And there is SecureRandom for security concerns.<p>Last fun fact Math.random() and a Monte Carlo test introduced "CAS in Java" and all that followed with JSR 166.
Reminded me an interesting Java Random issue with small seeds and power of two intervals:<p><pre><code> for(int i = 0; i < 256; i++) {
System.out.println(new Random(i).nextInt(8));
}
</code></pre>
It returns same number for all seeds.
I tested a similar attack against ApacheCommons' RandomStringUtil. Given a few bytes of output, I could recover the RNG state in 20 minutes on CPU.
As another commenter has said, Firefox doesn't use Rhino. Here's the relevant code in Firefox's JS engine.<p><a href="http://dxr.mozilla.org/mozilla-central/source/js/src/jsmath.cpp#765" rel="nofollow">http://dxr.mozilla.org/mozilla-central/source/js/src/jsmath....</a>
Hah, funny! I recently did the same to circumvent CSRF-protection based on java.util.Random. Here's my solver in JS: <a href="https://peks.as/experiments/random/" rel="nofollow">https://peks.as/experiments/random/</a>