kernel/common/kernel.rb
#--
# NOTE: This isn't quite MRI compatible.
# We don't seed the RNG by default with a combination of time, pid and
# sequence number
#++
This isn't quite MRI compatible.
We don't seed the RNG by default with a combination of time, pid and
sequence number
This isn ' t quite MRI compatible . We don ' t seed the RNG by default with a combination of time pid and sequence number
def srand(seed=0)
    cur = Kernel.current_srand
    if seed == 0
      begin
        File.open("/dev/urandom", "r") do |f|
          seed = f.read(10).unpack("I*")[0]
        end
      rescue Errno::ENOENT, Errno::EPERM, Errno::EACCES
        seed = Time.now.to_i
      end
    end
    Platform::POSIX.srand(seed.to_i)
    Kernel.current_srand = seed.to_i
    cur
  end
def srand ( seed = 0 ) cur = Kernel . current_srand if seed == 0 begin File . open ( "/dev/urandom" , "r" ) do | f | seed = f . read ( 10 ) . unpack ( "I*" ) [ 0 ] end rescue Errno :: ENOENT , Errno :: EPERM , Errno :: EACCES seed = Time . now . to_i end end Platform :: POSIX . srand ( seed . to_i ) Kernel . current_srand = seed . to_i cur end
NOTE: This isn't quite MRI compatible.
NOTE : This isn ' t quite MRI compatible .
seed
<not_specific>