Math.random的用法

接触随机数,随机产生一个随机数,产生随机数的方法接触到了Math.random(),产生一个0.0到1.0的随机数double值,不包括1.0,即[0.0,1.0)
使用Math.random()方法随机产生[0.0,16.0)
int number =(int)(Math.random()16);
使用Math.random()方法产生随机数[44.0,55.0)
int number = (int)(44.0+Math.random()
(55-44))
使用Math.random()方法产生随机数[44.0,55.0]
int number = (int)(44.0+Math.random()*(55-44+1))

posted @ 2021-03-05 17:18  李家成  阅读(890)  评论(0)    收藏  举报