Skip to content

Instantly share code, notes, and snippets.

@SteveFromTheOffice
Last active October 10, 2019 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveFromTheOffice/c8448a09352337386f135a16bbb20d93 to your computer and use it in GitHub Desktop.
Save SteveFromTheOffice/c8448a09352337386f135a16bbb20d93 to your computer and use it in GitHub Desktop.
Javascript IOTA Seed Generator
var GenerateSeed = function () {
var length = 81; // The length of the seed and int array.
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"; // The allowed characters in the seed.
var randomValues = new Uint32Array(length); // An empty array to store the random values.
var result = new Array(length); // An empty array to store the seed characters.
window.crypto.getRandomValues(randomValues); // 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.
};
GenerateSeed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment