(1)So I first thought a seed is something that starts the random number as the book says "s a number used to initialize a random number generator".So random numbers should start with seed, which is not the case.Please explain.
(2) Using seed and java API java.util.Random, I want to generate 10 random numbers with bound 300-1000.However, the following code giving me all same numbers:
import java.util.*;
public class RandomClassTest {
public static void main(String [] args) {
Random rd = new Random(300);
int randInt = rd.nextInt(1000-300)+300;
int count = 1;
while( count <= 10) {
System.out.println(randInt);
count++;
}
}
}
My output:
743
743
743
743
743
743
743
743
743
743
// all the time same output without any variation
Aucun commentaire:
Enregistrer un commentaire