Enumerable (Module)

In: rand.rb

rand.rb — library for picking random elements and shuffling

Copyright (C) 2004 Ilmari Heikkinen <kig@misfiring.net>

Documentation:Christian Neukirchen <chneukirchen@gmail.com>

Methods

Public Instance methods

Calls block once for each element in self in random order, passing that element as a parameter.

[Source]

    # File rand.rb, line 25
25:   def each_random(&block)
26:     shuffle.each(&block)
27:   end

Invokes block once for each element of self in random order. Creates a new array containing the values returned by the block.

[Source]

    # File rand.rb, line 31
31:   def map_random(&block)
32:     shuffle.map(&block)
33:   end

Choose and return a random element of the Enumerable.

  [1, 2, 3, 4].pick  #=> 2 (or 1, 3, 4)

[Source]

    # File rand.rb, line 13
13:   def pick
14:     entries.pick
15:   end

Return an array of the elements in random order.

  [1, 2, 3, 4].shuffle  #=> [3, 4, 1, 2]

[Source]

    # File rand.rb, line 19
19:   def shuffle
20:     entries.shuffle
21:   end

[Validate]