faker-ruby/faker · error · ArgumentError

min_alpha must be greater than or equal to 0

Error message

min_alpha must be greater than or equal to 0

What it means

Error "min_alpha must be greater than or equal to 0" thrown in faker-ruby/faker.

Source

Thrown at lib/faker/default/alphanumeric.rb:49

      #
      # @param number [Integer] The number of characters to generate
      # @param min_alpha [Integer] The minimum number of alphabetic to add to the string
      # @param min_numeric [Integer] The minimum number of numbers to add to the string
      #
      # @return [String]
      #
      # @example
      #   Faker::Alphanumeric.alphanumeric(number: 10) #=> "3yfq2phxtb"
      # @example
      #   Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3) #=> "3yfq2phxtb"
      # @example
      #   Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3) #=> "3yfq2phx8b"
      #
      # @faker.version 2.1.3
      def alphanumeric(number: 32, min_alpha: 0, min_numeric: 0)
        char_count = resolve(number)
        return '' if char_count.to_i < 1
        raise ArgumentError, 'min_alpha must be greater than or equal to 0' if min_alpha&.negative?
        raise ArgumentError, 'min_numeric must be greater than or equal to 0' if min_numeric&.negative?

        return Array.new(char_count) { sample(ALPHANUMS) }.join if min_alpha.zero? && min_numeric.zero?

        raise ArgumentError, 'min_alpha + min_numeric must be <= number' if min_alpha + min_numeric > char_count

        random_count = char_count - min_alpha - min_numeric

        alphas = Array.new(min_alpha) { sample(self::LLetters) }
        numbers = Array.new(min_numeric) { sample(self::Numbers) }
        randoms = Array.new(random_count) { sample(ALPHANUMS) }

        combined = alphas + numbers + randoms
        shuffle!(combined).join
      end
    end
  end
end

View on GitHub (pinned to cca4184947)

When it happens

Trigger: Thrown at lib/faker/default/alphanumeric.rb:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21). Data as JSON: /api/errors/ac567a9ab998f874. Report an issue: GitHub.