summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/fqdn_rand.rb
blob: 9297539e311023a3a7616d08ab5c7d12970cedc1 (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