Created
December 31, 2019 14:01
-
-
Save piksel/922281d9be89d5fd3e02970dd9ccaaf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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