{"record":{"id":"f34453895320796a","repo":"bchavez/Bogus","slug":"max-digit-can-t-be-lager-than-9-or-smaller-than-0","errorCode":null,"errorMessage":"max digit can't be lager than 9 or smaller than 0","messagePattern":"max digit can't be lager than 9 or smaller than 0","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Randomizer.cs","lineNumber":66,"sourceCode":"\n   /// <summary>\n   /// Get an int from 0 to max.\n   /// </summary>\n   /// <param name=\"max\">Upper bound, inclusive.</param>\n   public int Number(int max)\n   {\n      return Number(0, max);\n   }\n\n   /// <summary>\n   /// Get a random sequence of digits.\n   /// </summary>\n   /// <param name=\"count\">How many</param>\n   /// <param name=\"minDigit\">minimum digit, inclusive</param>\n   /// <param name=\"maxDigit\">maximum digit, inclusive</param>\n   public int[] Digits(int count, int minDigit = 0, int maxDigit = 9)\n   {\n      if( maxDigit is > 9 or < 0 ) throw new ArgumentException(\"max digit can't be lager than 9 or smaller than 0\", nameof(maxDigit));\n      if( minDigit is > 9 or < 0 ) throw new ArgumentException(\"min digit can't be lager than 9 or smaller than 0\", nameof(minDigit));\n\n      var digits = new int[count];\n      for( var i = 0; i < count; i++ )\n      {\n         digits[i] = Number(min: minDigit, max: maxDigit);\n      }\n      return digits;\n   }\n\n   /// <summary>\n   /// Get an int from min to max.\n   /// </summary>\n   /// <param name=\"min\">Lower bound, inclusive</param>\n   /// <param name=\"max\">Upper bound, inclusive</param>\n   public int Number(int min = 0, int max = 1)\n   {\n      //lock any seed access, for thread safety.","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Randomizer.cs#L48-L84","documentation":"Thrown by Randomizer.Digits when maxDigit (or minDigit) is outside 0-9. The pattern 'maxDigit is > 9 or < 0' uses C# pattern matching; any value above 9 or below 0 is rejected. The same check runs for minDigit on the next line with a min-specific message.","triggerScenarios":"Calling f.Random.Digits(5, 0, 12) or f.Random.Digits(5, -1, 9). Passing a digit bound outside the single-digit range.","commonSituations":"Configuring a digit generator from external config without clamping, or assuming the bounds are base-N rather than base-10 digit range.","solutions":["Clamp maxDigit and minDigit to the inclusive range 0..9 before calling Digits.","Validate config-supplied bounds against 0..9 at load time.","If you need values beyond 9, use Number(min,max) per position instead of Digits."],"exampleFix":"// before\nvar d = f.Random.Digits(4, minDigit: 0, maxDigit: 15);\n// after\nvar d = f.Random.Digits(4, minDigit: 0, maxDigit: 9);","handlingStrategy":"validation","validationCode":"static int[] SafeDigits(Bogus.Randomizer r, int count, int minDigit, int maxDigit) {\n    if (minDigit < 0 || minDigit > 9) throw new ArgumentOutOfRangeException(nameof(minDigit));\n    if (maxDigit < 0 || maxDigit > 9) throw new ArgumentOutOfRangeException(nameof(maxDigit));\n    return r.Digits(count, minDigit, maxDigit);\n}","typeGuard":null,"tryCatchPattern":"try { return r.Digits(count, minDigit, maxDigit); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"digit\")) {\n    // clamp bounds and retry\n    return r.Digits(count, Math.Clamp(minDigit,0,9), Math.Clamp(maxDigit,0,9));\n}","preventionTips":["Clamp digit bounds from config to 0..9.","Add a config schema validation for digit ranges.","Document that Digits is base-10 single-digit only."],"tags":["bogus","randomizer","digits","range-validation"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}