]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
fqdn_rotate: reset srand seed correctly on old ruby versions
authorDavid Schmitt <david.schmitt@puppetlabs.com>
Tue, 12 May 2015 14:01:55 +0000 (15:01 +0100)
committerDavid Schmitt <david.schmitt@puppetlabs.com>
Tue, 26 May 2015 13:25:43 +0000 (14:25 +0100)
Without this, the global seed is reseeded on every use
of fqdn_rotate, which is a waste. Older rubies might even use a
time-base seed which adversly impacts the quality of the RNG.

lib/puppet/parser/functions/fqdn_rotate.rb

index cf22d36813c0539e271457297323beff8cd1e7c7..d9741a02fee4fb877fc335e50296319b6fe20d90 100644 (file)
@@ -39,9 +39,9 @@ Rotates an array a random number of times based on a nodes fqdn.
       if defined?(Random) == 'constant' && Random.class == Class
         offset = Random.new(seed).rand(elements)
       else
-        srand(seed)
+        old_seed = srand(seed)
         offset = rand(elements)
-        srand()
+        srand(old_seed)
       end
     end
     offset.times {