Get random numbersTag(s): String/Number


public class MyTest {
    public static void main(String args[]) {
        new MyTest().doit();
    }

    public void doit() {
      java.util.Random rand = new java.util.Random();
      // random integer 0 to 10
      int max = 10;
      for (int i=0; i<10; i++) {
          System.out.println(rand.nextInt(max + 1));
      }
      // random double 0 to 10
      double maxd = 10;
      for (int i=0; i<10; i++) {
        System.out.println(maxd * rand.nextDouble());
      }
   }
}
The output
4
0
0
10
10
4
10
10
6
10
8.13013058393518
0.6631286078928067
4.382003543427801
7.2768144451559795
7.312852816962123
8.69257797289748
2.4967782036871657
4.451145854389913
1.82517092998838

blog comments powered by Disqus