Skip to content

Instantly share code, notes, and snippets.

@JokingChicken
Last active September 11, 2018 09:04
Show Gist options
  • Save JokingChicken/341b02ebb3b9313c05ab0b34274a9c68 to your computer and use it in GitHub Desktop.
Save JokingChicken/341b02ebb3b9313c05ab0b34274a9c68 to your computer and use it in GitHub Desktop.
create string of random 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;
}
@JokingChicken
Copy link
Author

JokingChicken commented Jun 18, 2018

this is used in my projectgreen project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment