Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generating a seed: a general approach
// 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
You can’t perform that action at this time.