# Random 0.2.1

**URL:** <https://www.ruby-forum.com/t/random-0-2-1/93901>\
**Category:** Ruby\
**Created:** [April 13, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/random-0-2-1/93901 "2006-04-13T15:53:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [April 13, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/random-0-2-1/93901/1 "2006-04-13T15:53:03Z")

</div>

Hi,

A first public release of Random is now available. See README below  
for details and get it from:

[http://rubyforge.org/projects/random/](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 F.

= 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/](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:

== Online Resources and References

- Documentation Home: coming!
- Project Page: [http://rubyforge.org/projects/random](http://rubyforge.org/projects/random)
- API Documents: coming!

== Simple Example

Once installed, you can use random as follows:

:include: doc/simple\_example.rb

== Credits

[**Richard Wagner**] 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](http://random.rubyforge.org). You can find the  
Random  
RubyForge page at [http://rubyforge.org/projects/random](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:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).

* * *

= Other stuff

Author:: Robert F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Requires:: Ruby 1.8.2 or later (but only tested with 1.8.4)  
License:: Copyright 2006 by Robert F.  
Released under a BSD-style license. See the LICENSE file  
included in the distribution.

---

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [April 13, 2006, 3:56pm UTC](https://www.ruby-forum.com/t/random-0-2-1/93901/2 "2006-04-13T15:56:05Z")

</div>

> 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
