Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Java random generator works?

Tags:

java

random

jvm

I wrote program that simulates dice roll

    Random r = new Random();
    int result = r.nextInt(6);
    System.out.println(result);

I want to know if there is a way to "predict" next generated number and how JVM determines what number to generate next?

Will my code output numbers close to real random at any JVM and OS?

like image 997
Davit Mumladze Avatar asked Feb 17 '16 11:02

Davit Mumladze


1 Answers

Yes, it is possible to predict what number a random number generator will produce next. I've seen this called cracking, breaking, or attacking the RNG. Searching for any of those terms along with "random number generator" should turn up a lot of results.

Read How We Learned to Cheat at Online Poker: A Study in Software Security for an excellent first-hand account of how a random number generator can be attacked. To summarize, the authors figured out what RNG was being used based on a faulty shuffling algorithm employed by an online poker site. They then figured out the RNG seed by sampling hands that were dealt. Once they had the algorithm and the seed, they knew exactly how the deck would be arranged after later shuffles.

You can also refer this link.

like image 167
Mohith P Avatar answered Oct 21 '22 20:10

Mohith P