Live data from Hacker News

Predicting the next Math.random() in Java

franklinta.com

1–10 of 58 posts

Re: Predicting the next Math.random() in Java

#6
post #3

How dangerous this prediction can be? I can't stop thinking of java-backended real money, poorly written, gaming websites.

It's well known. If someone is doing anything with real money, and isn't doing something more secure than this, they've already been hacked, are already out of business, and are already not allowed to write code that deals with real money.

Re: Predicting the next Math.random() in Java

#7
post #3

How dangerous this prediction can be? I can't stop thinking of java-backended real money, poorly written, gaming websites.

Real random numbers are useless because everything follow some distribution. Actually random generators in programming languages should be called pseudorandom to avoid confusions.

Re: Predicting the next Math.random() in Java

#8
If you want cryptographic-quality random numbers, both Java and Javascript have them. Math.random() is simply a super-fast decent RNG.

Example:

    var buf = new Uint32Array(10); 
    window.crypto.getRandomValues(buf);
    console.log(buf);
Outputs things like:

    [4027145128, 258543382, 1205615760, 2665675208, 4033127244, 
     2280027866, 3983484449, 510932333, 1911490534, 2609399642]
This works in Chrome and FF.

IE11 has Crypto.getRandomValues(...)

Java has SecureRandom:

http://docs.oracle.com/javase/6/docs/api/java/security/Secur...

Re: Predicting the next Math.random() in Java

#9
post #3

How dangerous this prediction can be? I can't stop thinking of java-backended real money, poorly written, gaming websites.

Those likely won't be vulnerable even if they implemented their site using the insecure random function. The reason why this works is that you're the only consumer of Java-randomness, as you add additional consumers it becomes infinitely more difficult.

Consumers also don't need to be users, AI players and cards dealt will also consume randomness. You would also need to know the mapping from the random output into the game (e.g. in card games are there multiple decks each assigned 1 value of entropy? 2 decks, 3 decks, etc? Plus any mappings or conversions will make this impossible (as you wouldn't know the real output of the random number generator)).

Ultimately it will likely work pretty reliably locally, but as soon as you stick it on a web service then all bets are off.

Post reply on HN