Last active
April 11, 2021 15:55
-
-
Save Elijah-trillionz/25ed2b79fe56f16cf404190f0116add7 to your computer and use it in GitHub Desktop.
How to randomly generate strong ids for project.
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
const letter = 'abcdefghijklmnopqrstuvwxyz'; | |
const allCharacters = `${letter}1234567890123456789123456789$&@*£€¥%${letter.toUpperCase()}`; | |
const allCharactersInArray = allCharacters.split(''); | |
function randomise() { | |
const randomCharacter = | |
allCharactersInArray[Math.floor(Math.random() * allCharactersInArray.length)]; | |
return randomCharacter; | |
} | |
function generateId() { | |
const suggest = []; | |
for (let i = 0; i < 16; i++) { | |
suggest.push(randomise()); | |
} | |
return suggest.join(''); // will generate a very strong id | |
} | |
console.log(generateId()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment