Class: Mysql::Random

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/vendor/mysql.rb

Instance Method Summary collapse

Constructor Details

#initialize(seed1, seed2) ⇒ Random

Returns a new instance of Random.



1149
1150
1151
1152
1153
# File 'lib/active_record/vendor/mysql.rb', line 1149

def initialize(seed1, seed2)
  @max_value = 0x3FFFFFFF
  @seed1 = seed1 % @max_value
  @seed2 = seed2 % @max_value
end

Instance Method Details

#rndObject



1155
1156
1157
1158
1159
# File 'lib/active_record/vendor/mysql.rb', line 1155

def rnd()
  @seed1 = (@seed1*3+@seed2) % @max_value
  @seed2 = (@seed1+@seed2+33) % @max_value
  @seed1.to_f / @max_value
end