码迷,mamicode.com
首页 > 其他好文 > 详细

产生随机数

时间:2018-08-11 19:39:42      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:方法   rand   随机   随机数   style   int   ble   new   一个   

在 [ min , max ] 之间产生一个随机整数

方法一 : int r = ( int ) min

    + Math.random( )  * ( max - min + 1 ) ;

方法二 :  int r = ( int )( min +

    new Random( ).nextDouble( )  * ( max - min + 1 )  ) ;

在 [ min , max ) 之间产生一个随机整数

 int r = ( int ) min + Math.random( )  * ( max - min  ) ;

 

产生随机数

标签:方法   rand   随机   随机数   style   int   ble   new   一个   

原文地址:https://www.cnblogs.com/zhwandzcx/p/9460689.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!