Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Created October 7, 2021 12:21
Show Gist options
  • Save ArtemAvramenko/c7a979661df5e0157cc64d0703d75415 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/c7a979661df5e0157cc64d0703d75415 to your computer and use it in GitHub Desktop.
Get unique array of letters in C#
public static string GetUniqueStringValue(int size)
{
var data = new byte[size];
using var crypto = RandomNumberGenerator.Create();
crypto.GetBytes(data);
for (var i = 0; i < size; i++)
{
data[i] = (byte)('a' + data[i] % 26);
}
return Encoding.ASCII.GetString(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment