Skip to content

Instantly share code, notes, and snippets.

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
// Complete description and story behind the snippet is available at:
//based on
//modified by Petr Zizka
var GenerateSeed = function () {
const length = 81; // The length of the seed and int array.
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"; // The allowed characters in the seed.
var result = new Array(length); // An empty array to store the seed characters.
var randomValues = Buffer.alloc(length)
// Generate random values and store them to array.
var cursor = 0; // A cursor is introduced to remove modulus bias.
for (var i = 0; i < randomValues.length; i++) { // Loop through each of the 81 random values.
cursor += randomValues[i]; // Add them to the cursor.
result[i] = chars[cursor % chars.length]; // Assign a new character to the seed based on cursor mod 81.
return result.join(''); // Merge the array into a single string and return it.
var NewSeed = GenerateSeed();
console.log("Length: %s", NewSeed.length)
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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.