Sha256: fc5a5a216436f3dcf3fd479e094e1bcf231a3ca594503908fd1e11679aa1556c
Contents?: true
Size: 613 Bytes
Versions: 3
Compression:
Stored size: 613 Bytes
Contents
# Splits an array into two groups, where the 1st group is a randomly selected # sample of the input (of the specified size) and the 2nd group is the remainder. # # This function takes 2 parameters: # * The array to split (Array) # * The number of items to sample from the array (Integer) # # Returns an array of [<sample>, <remainder>]. Puppet::Functions.create_function(:'canary::random_split') do dispatch :rand do param 'Array', :arr param 'Integer', :size end def rand(arr, size) canaries = arr.sample(size) rest = arr.reject { |r| canaries.include?(r) } [canaries, rest] end end
Version data entries
3 entries across 3 versions & 1 rubygems