X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fseeded_rand.rb;h=c51e248f487a39bd03fdf567735e718e8dccb618;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=44e27b8dc5451e404452bdfb9d2a14622727e8ac;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/seeded_rand.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/seeded_rand.rb index 44e27b8dc..c51e248f4 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/seeded_rand.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/seeded_rand.rb @@ -1,22 +1,32 @@ -Puppet::Parser::Functions::newfunction( +# +# seeded_rand.rb +# +Puppet::Parser::Functions.newfunction( :seeded_rand, :arity => 2, :type => :rvalue, - :doc => <<-EOS -Usage: `seeded_rand(MAX, SEED)`. MAX must be a positive integer; SEED is any string. + :doc => <<-DOC + @summary + Generates a random whole number greater than or equal to 0 and less than MAX, using the value of SEED for repeatable randomness. -Generates a random whole number greater than or equal to 0 and less -than MAX, using the value of SEED for repeatable randomness. If SEED -starts with "$fqdn:", this is behaves the same as `fqdn_rand`. + @return + random number greater than or equal to 0 and less than MAX -EOS + @example **Usage:** + seeded_rand(MAX, SEED). + MAX must be a positive integer; SEED is any string. + + Generates a random whole number greater than or equal to 0 and less + than MAX, using the value of SEED for repeatable randomness. If SEED + starts with "$fqdn:", this is behaves the same as `fqdn_rand`. +DOC ) do |args| require 'digest/md5' - raise(ArgumentError, "seeded_rand(): first argument must be a positive integer") unless function_is_integer([args[0]]) and args[0].to_i > 0 - raise(ArgumentError, "seeded_rand(): second argument must be a string") unless args[1].is_a? String + raise(ArgumentError, 'seeded_rand(): first argument must be a positive integer') unless function_is_integer([args[0]]) && args[0].to_i > 0 + raise(ArgumentError, 'seeded_rand(): second argument must be a string') unless args[1].is_a? String max = args[0].to_i seed = Digest::MD5.hexdigest(args[1]).hex - Puppet::Util.deterministic_rand(seed,max) + Puppet::Util.deterministic_rand(seed, max) end