Last active
September 24, 2019 10:30
-
-
Save Hribek25/c430cd8e7d9fe2c7be4ef996e6cb9065 to your computer and use it in GitHub Desktop.
Generating a seed: a general approach
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
// The snippet is a part of the IOTA Developer Essentials project. You can reach it at https://hribek25.github.io/IOTA101/ | |
// Complete description and story behind the snippet is available at: https://hribek25.github.io/IOTA101/Allchapters_csharp.ipynb.html#67D98D069B61 | |
//based on https://github.com/siqniz/IOTA-Random-Seed-Generator | |
using System.Security.Cryptography; | |
private static string NewRandomSeed() | |
{ | |
string iotaseed = string.Empty; | |
using (RNGCryptoServiceProvider _ran = new RNGCryptoServiceProvider()) // The class provides crypto-safe random generator | |
{ | |
string[] _seed = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "9" }; | |
byte[] _data = new byte[8]; //8 bytes to hold an unsigned bits int | |
for (int i = 0; i <= 80; i++) //The number times this will run in orde to fill the 81 char requirment | |
{ | |
_ran.GetBytes(_data); | |
var gennum = BitConverter.ToUInt64(_data, 0); | |
var _num = (gennum % 27); | |
iotaseed += _seed[_num]; | |
} | |
} | |
return iotaseed; | |
} | |
Console.WriteLine(NewRandomSeed()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment