公式:假设你要产生5到10之间的随机数,可以用下面方法:
int Min = 5;
int Max = 10;
int result = Min + (int)(Math.random() * ((Max - Min) + 1));

例如:
生成5-26之间的随机数,包括26
int randNum = rand.nextInt(22)+5;

 

相关文章:

  • 2022-02-10
  • 2021-09-25
  • 2022-02-12
  • 2021-09-26
  • 2021-11-29
  • 2021-12-01
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-08-03
相关资源
相似解决方案