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

后端 未结 7 855
情话喂你
情话喂你 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);
    
    0 讨论(0)
提交回复
热议问题