Class Random
In: lib/more/facets/random.rb
Parent: Object

Randomization Extensions

This library extends Array, String, Hash and other classes with randomization methods. Most of the methods are of one of two kinds. Either they "pick" a random element from the reciever or they randomly "shuffle" the reciever.

The most common example is Array#shuffle, which simply randmomizes the order of an array‘s elements.

  [1,2,3].shuffle  #~> [2,3,1]

The other methods do similar things for their respective classes.

The classes are all extended via mixins which have been created within Ruby‘s Random class.

Credit for this work is due to:

  • Ilmari Heikkinen
  • Christian Neukirchen
  • Thomas Sawyer

NOTE: Inline QED tests are almost pointless here b/c… yea, it‘s random. So indtead of the usual `#=>` we use `#~>` which means approx. equal and prevens QED from making a hard assertion.

Methods

letter  

Classes and Modules

Module Random::ArrayExtensions
Module Random::HashExtensions
Module Random::IntegerExtensions
Module Random::NumericExtensions
Module Random::RangeExtensions
Module Random::StringExtensions

External Aliases

rand -> number
  Alias for Kernel#rand.

Public Class methods

Module method to generate a random letter.

  Random.letter  #~> "q"
  Random.letter  #~> "r"
  Random.letter  #~> "a"

[Validate]