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