This commit is contained in:
nub31
2025-07-22 23:24:30 +02:00
parent 4ec44195ed
commit efe13730e7
15 changed files with 7 additions and 43 deletions

View File

@@ -0,0 +1,38 @@
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;
}
}