summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/fqdn_rand.rb
blob: 3e7018ac4228e42832b608e995d17695ce5db25c (plain)
1
2
3
4
5
6
7
8
9
Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
  "Generates random numbers based on the node's fqdn. The first argument
  sets the range.  Additional (optional) arguments may be used to further
  distinguish the seed.") do |args|
    require 'md5'
    max = args.shift
    srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
    rand(max).to_s
end