Last active
September 11, 2018 09:04
-
-
Save JokingChicken/341b02ebb3b9313c05ab0b34274a9c68 to your computer and use it in GitHub Desktop.
create string of random characters
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
//make a random id with specified length, and get chars out of specified string | |
function makeid(length, string) { | |
var text = ""; | |
//the list of chars to pick chars for id | |
var possible = (string ? string : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); | |
//iterate over every char, with default length of 8 characters | |
while (text.length < (length ? length : 8)) { | |
//add a random picked char from "possible" | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is used in my projectgreen project