<commit_before>#
# seeded_rand.rb
#
Puppet::Parser::Functions.newfunction(
  :seeded_rand,
  :arity => 2,
  :type => :rvalue,
  :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.

    @return
      random number greater than or equal to 0 and less than MAX

    @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]]) && 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)
end<commit_msg>seeded_rand: update funtion to ensure it returns an int not String<commit_after>#
# seeded_rand.rb
#
Puppet::Parser::Functions.newfunction(
  :seeded_rand,
  :arity => 2,
  :type => :rvalue,
  :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.

    @return
      random number greater than or equal to 0 and less than MAX

    @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]]) && 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_int(seed, max)
end
{'fraction_non_alphanumeric': 0.10013233348037054, 'fraction_numerical': 0.0105866784296427, 'mean_word_length': 3.8152866242038215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1777155', 'n_tokens_mistral': 745, 'n_tokens_neox': 713, 'n_words': 273}