How do you use math.random to generate random ints?

后端 未结 7 887
情话喂你
情话喂你 2020-12-06 01:23

How do you use Math.random to generate random ints?

My code is:

int abc= (Math.random()*100);
System.out.println(abc);

All it print

7条回答
  •  借酒劲吻你
    2020-12-06 01:59

    You can also use this way for getting random number between 1 and 100 as:

    SecureRandom src=new SecureRandom();
    int random=1 + src.nextInt(100);
    

提交回复
热议问题