如何获得一个随机数:10~99

int value = (int)(Math.random() * 90 + 10);
Math.random()--随机获得一个[0.0,1.0)之间的数
* 90之后变成[0.0,90.0)
+ 10之后变成[10.0,100.0)
(int)强转之后从原来的浮点型变成整型[10,99)
(99是因为100取不到,整型取99)

posted @ 2022-06-09 17:20  催是什么崔  阅读(201)  评论(0编辑  收藏  举报