Hi, A first public release of Random is now available. See README below for details and get it from: http://rubyforge.org/projects/random/ It has only been tested on linux so far and is only available as a gem. If someone is willing to compile it on windows and mac os x so we can have pre-compiled gems please email me. Best regards and happy easter, Robert Feldt = Random - Ruby classes for pseudorandom number generation This package contains Random, a ruby extension adding classes for generating pseudorandom number generation (PRNG). Random has the following features: * A fast PRNG implemented in C and wrapped in a Ruby class. The algorithm is the well-known and widely used MersenneTwister. * Multiple independent random streams can be active at the same time (since the PRNG is wrapped in a class and objects of that class are independent). * PRNG objects supports marshaling. This is in contrast to Ruby's standard srand/rand methods. Even though the standard methods use the same PRNG algorithm (the MersenneTwister) only a single (global) PRNG exists for each ruby invocation and its state cannot be saved to disc. Random alleviates these problems. This is especially important for scientific and simulation applications. == Download The latest version of Random can be found at * http://rubyforge.org/projects/random/ == Installation === GEM Installation Download and install Random with the following. gem install --remote random === Running the Random Test Suite Random comes with an extensive test suite. If you wish to run it: * CD into the top project directory of random. * Type: rake # If you have a version of rake installed == Online Resources and References * Documentation Home: coming! * Project Page: http://rubyforge.org/projects/random * API Documents: coming! == Simple Example Once installed, you can use random as follows: :include: doc/simple_example.rb == Credits [<b>Richard Wagner</b>] For the C++ implementation of the MersenneTwister which is the basis for Random::MersenneTwister. == License Random is available under a BSD-style license. :include: LICENSE == Support The Random homepage is http://random.rubyforge.org. You can find the Random RubyForge page at http://rubyforge.org/projects/random. Feel free to submit commits or feature requests. If you send a patch, please also update and send the corresponding unit tests. It would be great to get help with creating pre-compiled gems of this to simplify for users that do not have a build environment. Please email if you can help with this (especially for non-linux targets). For other information, feel free to ask on the ruby-talk mailing list (which is mirrored to comp.lang.ruby) or contact mailto:firstname.lastname@example.org. --- = Other stuff Author:: Robert Feldt <email@example.com> Requires:: Ruby 1.8.2 or later (but only tested with 1.8.4) License:: Copyright 2006 by Robert Feldt Released under a BSD-style license. See the LICENSE file included in the distribution.
on 2006-04-13 15:53
on 2006-04-13 15:56
> 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