Hi I wonder if somebody can help me with this. This programs simulates throwing a die 20 times:
import java.util.Random; // program uses class Random
public class RandomIntegers
{
public static void main( String[] args )
{
Random randomNumbers = new Random(); // random number generator
int face; // stores each random integer generated
// loop 20 times
for ( int counter = 1; counter <= 20; counter++ )
{
// pick random integer from 1 to 6
face = 1 + randomNumbers.nextInt( 6 );
System.out.printf( "%d ", face ); // display generated value
// if counter is divisible by 5, start a new line of output
if ( counter % 5 == 0 )
System.out.println();
} // end for
} // end main
} // end class RandomIntegers
I have read that often - maybe not in this instance but in general - for debugging purposes it helps to be able to generate always the same sequence of number, and to achieve that rather than having Random randomNumbers = new Random();
we should provide a seed argument like this Random randomNumbers = new Random(seedValue);
So if I change that particular line in the above program to something like Random randomNumbers = new Random(15);
the sequence of numbers generated is always the same at each roll of the die. Now, my question now is this: which number should I use as seed? I mean can I use any number, say 1, 30, 34, 100? What is the difference between one number or the other one? SO what's the difference if I do Random randomNumbers = new Random(15);
or if I do Random randomNumbers = new Random(25);
I mean the seed is where the random generator is supposed to start generating numbers from?Uhm...maybe I need some clarifications on that...
thanks