Files
nub-lang/src/compiler/NubLang/HexString.cs
nub31 efe13730e7 ...
2025-07-22 23:24:30 +02:00

38 lines
770 B
C#

namespace NubLang;
public static class HexString
{
private static readonly HashSet<string> _used = [];
private static readonly char[] StringChars = "0123456789abcdef".ToArray();
public static string CreateUnique(int length)
{
string hex;
while (true)
{
hex = Create(length);
if (_used.Add(hex))
{
break;
}
}
return hex;
}
public static string Create(int length)
{
var rand = new Random();
var hexString = "";
for (var i = 0; i < length; i++)
{
var randIndex = rand.Next(0, StringChars.Length);
hexString += StringChars[randIndex];
}
return hexString;
}
}