2 comments:

BobaFett said...

If no argument constructor for java.util.Random in the JDK you use, you can "System.currentTimeMillis ()" parameter, as long as the seed used.

For the next random number from the generator in the range 0-51, inclusive, simple, "nextInt (52).

eg

import java.util.Random;

long seed = System.currentTimeMillis ();
Random random = new Random (seed);
int i = random.nextInt (52);

Michael from UK said...

Very good - I guess the bridge is initialized before you call that?

However, observations of Math.random (I assume that most pseudo-random numbers work the same), because they, at random numbers in the order indicated the same tendency to give the initial value.

Thus, instead of the production with Math.random () in the loop, you need the seeds initialized before the loop and pass as a parameter when the interior.

This will ensure a new sequence each time, thus preventing the shuffle, so that the same cards each time. It is typical for a time (or I / O function) Source Math.random the first call, for example, the time in milliseconds, as always when Math.random not offer a new way to sequence each time. This means that you cannextInt random method instead of "restart" sequence every time.

Edit
****
In terms of documentation, using each new Random object to initialize the default time for the seeds to create a chance in the loop, and within nextInt select the next random number.

Post a Comment

Newer Post Older Post Home