Call nextGaussian() to get next double value centered at 0.0 with a standard deviation of 1.0.
/*
* Output:
0.9858761222419792
-1.0868562994825026
-1.2801148369647788
0.03988775024786847
-1.8662098370799078
-0.12277520073012224
0.0911032879532435
-0.0804314384368678
-2.3955991772544114
-1.857516970646183
*/
import java.util.Random;
public class MainClass {
public static void main(String args[]) {
Random generator = new Random();
for(int i = 0; i < 10; i++) {
System.out.println(generator.nextGaussian());
}
}
}
Home
Java Book
Essential Classes
Java Book
Essential Classes
Random:
- Random
- Call nextInt() to get random integers
- call nextDouble() to get next random double value
- Call nextGaussian() to get next double value centered at 0.0 with a standard deviation of 1.0.