From: Robert Feldt Date: 2006-04-13T22:54:46+09:00 Subject: Re: [ANN] Random 0.2.1 > Once installed, you can use random as follows: > > :include: doc/simple_example.rb > Oops, this should be: require 'rubygems' require 'random' mt = Random::RNG.new() mt.rand # like Ruby's normal rand mt.rand_num(1, 6) # gives a random integer in 1..6 mt.rand_float_exclusive # gives random float >= 0.0 and < 1.0 mt.rand_float # gives random float >= 0.0 and <= 1.0 mt.rand_int_with_bits(1000) # gives random integer with 1000 random bits mt.rand_bytes(10) # gives a random string of length 10 mt.next # next random number in RNG stream (typically an # integer >= 0 and < 2**32) str = Marshal.dump(mt) # Marshal the full state of mt to a string mt2 = Marshal.load(str) # and read it back in. mt2.next == mt.next # => true a = (1..100).to_a a.random_element # gives a random element from the array