Skip to content

Instantly share code, notes, and snippets.

@piksel
Created December 31, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piksel/922281d9be89d5fd3e02970dd9ccaaf7 to your computer and use it in GitHub Desktop.
Save piksel/922281d9be89d5fd3e02970dd9ccaaf7 to your computer and use it in GitHub Desktop.
public class KeySeeder
{
const int KeySize = 8;
private Random random;
private int currIndex = 0;
private char[] keyBuffer = new char[KeySize];
private char[] keyChars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_".ToCharArray();
public KeySeeder(int seed)
{
random = new Random(seed);
}
public string GetKey(int index)
{
if (index < currIndex) throw new Exception($"Index {index} is lower than current index {currIndex}");
for(; index > currIndex; currIndex++)
{
for (int i = 0; i < KeySize; i++)
{
keyBuffer[i] = keyChars[random.Next(keyChars.Length - 1)];
}
}
return new string(keyBuffer);
}
}
var ks = new KeySeeder(39329);
Console.WriteLine($"Key #1: {ks.GetKey(1)}");
Console.WriteLine($"Key #2: {ks.GetKey(2)}");
Console.WriteLine($"Key #3: {ks.GetKey(3)}");
Console.WriteLine($"Key #4: {ks.GetKey(4)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment