{"record":{"id":"e302a6e710457565","repo":"bchavez/Bogus","slug":"alphabet-must-contain-at-least-4-unique-characters","errorCode":null,"errorMessage":"alphabet must contain at least 4 unique characters.","messagePattern":"alphabet must contain at least 4 unique characters\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Hashids.cs","lineNumber":56,"sourceCode":"\n   /// <summary>\n   /// Instantiates a new Hashids en/de-coder.\n   /// </summary>\n   /// <param name=\"salt\"></param>\n   /// <param name=\"minHashLength\"></param>\n   /// <param name=\"alphabet\"></param>\n   public Hashids(string salt = \"\", int minHashLength = 0, string alphabet = DEFAULT_ALPHABET, string seps = DEFAULT_SEPS)\n   {\n      if( string.IsNullOrWhiteSpace(alphabet) )\n         throw new ArgumentNullException(\"alphabet\");\n\n      this.salt = salt;\n      this.alphabet = string.Concat(alphabet.Distinct());\n      this.seps = seps;\n      this.minHashLength = minHashLength;\n\n      if( this.alphabet.Length < 16 )\n         throw new ArgumentException(\"alphabet must contain at least 4 unique characters.\", \"alphabet\");\n\n      this.SetupSeps();\n      this.SetupGuards();\n   }\n\n   /// <summary>\n   /// Encodes the provided numbers into a hashed string\n   /// </summary>\n   /// <param name=\"numbers\">the numbers to encode</param>\n   /// <returns>the hashed string</returns>\n   public virtual string Encode(params int[] numbers)\n   {\n      return this.GenerateHashFrom(numbers.Select(n => (long)n).ToArray());\n   }\n\n   /// <summary>\n   /// Encodes the provided numbers into a hashed string\n   /// </summary>","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Hashids.cs#L38-L74","documentation":"Thrown by the Hashids constructor when the deduplicated alphabet contains fewer than 16 characters. Note: the message text says 'at least 4 unique characters' but the actual guard is MIN_ALPHABET_LENGTH (16); this is a known message/code mismatch. The deduplication (alphabet.Distinct()) happens before the check, so duplicate characters count only once.","triggerScenarios":"Constructing new Hashids(alphabet: \"abc\") or any custom alphabet whose Distinct() result is shorter than 16 characters. Also triggered by passing a long string with many repeated characters that collapses to <16 unique ones.","commonSituations":"Customizing the Hashids alphabet with a short or repetitive character set; migrating from another hashid library with a smaller alphabet.","solutions":["Supply an alphabet with at least 16 unique characters (the default DEFAULT_ALPHABET has 62).","Remove duplicate characters from your custom alphabet and recount the unique set.","If a short alphabet is mandatory, fork or wrap Hashids since the 16-char minimum is hardcoded."],"exampleFix":"// before\nvar h = new Hashids(\"salt\", 0, \"abcd1234\");\n// after\nvar h = new Hashids(\"salt\", 0, Hashids.DEFAULT_ALPHABET);","handlingStrategy":"validation","validationCode":"static Hashids MakeHashids(string salt, string alphabet) {\n    var unique = alphabet.Distinct().Count();\n    if (unique < 16) throw new InvalidOperationException($\"alphabet has {unique} unique chars; need >=16\");\n    return new Hashids(salt, 0, alphabet);\n}","typeGuard":null,"tryCatchPattern":"try { return new Hashids(salt, 0, alphabet); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"alphabet\")) {\n    // fall back to default alphabet\n    return new Hashids(salt);\n}","preventionTips":["Default to Hashids.DEFAULT_ALPHABET unless a custom one is required.","Count unique chars before constructing.","Document the 16-char minimum at every config site."],"tags":["bogus","hashids","config","alphabet"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}