Class: Random

Inherits:
Object show all
Defined in:
lib/garcon/core_ext/random.rb

Overview

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.

Defined Under Namespace

Modules: ArrayExtensions, HashExtensions, IntegerExtensions, NumericExtensions, RangeExtensions, StringExtensions

Class Method Summary collapse

Class Method Details

.letterString

Module method to generate a random letter.

Examples:

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

Returns:

  • (String)

    A random letter



58
59
60
61
# File 'lib/garcon/core_ext/random.rb', line 58

def self.letter
  (SecureRandom.random_number(26) +
  (SecureRandom.random_number(2) == 0 ? 65 : 97)).chr
end