Shuffle and pick elements at random.
rand is a library for Ruby,
provided under the terms of the
It should not be confused with the
method in Ruby core.
This library provides helper methods mixed in to
These methods allow you to easily shuffle the order of elements or
pick an element at random.
It should be noted that the Facets project includes some functionality similar to this library, although the algorithms used are different. This library should be considered a lightweight alternative.
Methods are provided to:
pick_valueand destructive versions suffixed with
It also provides these facilities in String:
shuffle_charsto arrange the characters of the string in new order.
pick_indexto return random bytes, characters or elements.
Currently there are two ways to get the rand library:
Install the RubyGem. Recommended. Just do this:
gem install rand
That's it. Enjoy!
Download from RubyForge. tgz and zip files are available in the Files section.
setup.rb installer script is provided:
You may need superuser access to run the installer, depending on your system configuration.
Check out the latest code from the Subversion repository.
The repository URI for the latest library code in Subversion (known as the 'trunk') is:
You'll want to use this method if you are interested in following the development of the rand library or if you just want to try out the latest code. The code in Subversion should always work, but no guarantee can be made since it is expected to change frequently.
A Subversion client is required to check out code from the repository. Many different clients are available; you should select an appropriate client for your development environment. Once a client has been installed, run the checkout command. See the documentation for your chosen client for details. Provide the repository URI (noted above) when requested.
For example, with the classic command line Subversion client, you would run a command like this:
svn checkout svn://rubyforge.org/var/svn/rand/trunk/rand
Copyright 2007 Keegan Quinn. This page can be redistributed and/or modified under the terms of the WTFPL. It comes without any warranty, to the extent permitted by applicable law.