lib/garcon/core_ext/random.rb
# Generates random subarrays. Uses random numbers and bit-fiddling to assure
# performant uniform distributions even for large arrays.
#
# @example
#   a = *1..5
#   a.rand_subarrays(2) # => [[3, 4, 5], []]
#   a.rand_subarrays(3) # => [[1], [1, 4, 5], [2, 3]]
#
Generates random subarrays. Uses random numbers and bit-fiddling to assure
performant uniform distributions even for large arrays.
Generates random subarrays . Uses random numbers and bit - fiddling to assure performant uniform distributions even for large arrays .
def rand_subarrays(n = 1)
      raise ArgumentError, 'negative argument' if n < 0
      (1..n).map do
        r = rand(2**self.size)
        self.select.with_index { |_, i| r[i] == 1 }
      end
    end
def rand_subarrays ( n = 1 ) raise ArgumentError , 'negative argument' if n < 0 ( 1 .. n ) . map do r = rand ( 2 ** self . size ) self . select . with_index { | _ , i | r [ i ] == 1 } end end
Generates random subarrays.
Generates random subarrays .
n
<not_specific>
example
None