rand

rand

ri

 ------------------------------------------------------------ Kernel#rand
      rand(max=0)    => number
 ------------------------------------------------------------------------
      Converts _max_ to an integer using max1 = max .to_i.abs . If the
      result is zero, returns a pseudorandom floating point number
      greater than or equal to 0.0 and less than 1.0. Otherwise, returns
      a pseudorandom integer greater than or equal to zero and less than
      max1.  Kernel::srand  may be used to ensure repeatable sequences of
      random numbers between different runs of the program. Ruby
      currently uses a modified Mersenne Twister with a period of
      219937-1.
 
         srand 1234                 #=> 0
         [ rand,  rand ]            #=> [0.191519450163469, 0.49766366626136]
         [ rand(10), rand(1000) ]   #=> [6, 817]
         srand 1234                 #=> 1234
         [ rand,  rand ]            #=> [0.191519450163469, 0.49766366626136]
 

refe

 Kernel#rand
 --- rand([max=0])
 
     0 以上 max 未満の範囲の整数乱数を発生します。ま
     だsrand が呼ばれていなければ自動的に
     srand を呼び出します。
 
     maxnil または 0 を指定すると 0 以上 1 未
     満の実数値 Float乱数を与えます。
 

* はてなダイアリーキーワード:rand