lib/garcon/core_ext/random.rb
# Returns a random subset of an Array. If a _number_ of elements is
# specified then returns that number of elements, otherwise returns a random
# number of elements upto the size of the Array.
#
# By defualt the returned values are exclusive of each other, but if
# _exclusive_ is set to `false`, the same values can be choosen more than
# once.
#
# When _exclusive_ is <tt>true</tt> (the default) and the _number_ given is
# greater than the size of the array, then all values are returned.
#
# @example
#   [1, 2, 3, 4].rand_subset(1)        # => [2]
#   [1, 2, 3, 4].rand_subset(4)        # => [2, 1, 3, 4]
#   [1, 2, 3, 4].rand_subset           # => [1, 3, 4]
#   [1, 2, 3, 4].rand_subset           # => [2, 3]
#
Returns a random subset of an Array. If a _number_ of elements is
specified then returns that number of elements, otherwise returns a random
number of elements upto the size of the Array.

By defualt the returned values are exclusive of each other, but if
_exclusive_ is set to `false`, the same values can be choosen more than
once.

When _exclusive_ is true (the default) and the _number_ given is
greater than the size of the array, then all values are returned.
Returns a random subset of an Array . If a _number_ of elements is specified then returns that number of elements otherwise returns a random number of elements upto the size of the Array . By defualt the returned values are exclusive of each other but if _exclusive_ is set to ` false ` the same values can be choosen more than once . When _exclusive_ is true ( the default ) and the _number_ given is greater than the size of the array then all values are returned .
def rand_subset(number = nil, exclusive = true)
      number = SecureRandom.random_number(size) unless number
      number = number.to_int
      return sort_by{rand}.slice(0,number) if exclusive
      ri =[]; number.times { |n| ri << SecureRandom.random_number(size) }
      return values_at(*ri)
    end
def rand_subset ( number = nil , exclusive = true ) number = SecureRandom . random_number ( size ) unless number number = number . to_int return sort_by { rand } . slice ( 0 , number ) if exclusive ri = [ ] ; number . times { | n | ri << SecureRandom . random_number ( size ) } return values_at ( * ri ) end
Returns a random subset of an Array.
Returns a random subset of an Array .
number
<not_specific>
exclusive
<not_specific>
example
None