10 examples of 'random id generator javascript' in JavaScript

Every line of 'random id generator javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
2function generateID() {
3 let str = '';
4 for (let i = 0; i < 16; i += 1) {
5 str += chars[Math.floor(Math.random() * chars.length)];
6 }
7 return str;
8}
6function generateId() {
7 let text = "";
8 const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9
10 for (let i = 0; i < 60; i++)
11 text += possible.charAt(Math.floor(Math.random() * possible.length));
12
13 return text;
14}
1export function generateID(): string {
2 return Math.random().toString(36).substr(2);
3}
45function getId() {
46 return getRandomNumber(0, 10);
47}
1export function generateRandomId() {
2 return Math.floor(Math.random() * 1000000000);
3}
220function generateRandomId() {
221 return (Math.round(Math.random() * 1e12)).toString(36).substring(0, 10);
222}
30function id() {
31 return String.fromCharCode('a'.charCodeAt(0) + choice(3))
32}
6function createId () {
7 return (
8 Math.random().toString(16).substring(2)
9 + Math.random().toString(16).substring(2)
10 )
11}
5function generateRandomId() {
6 return Math.random().toString();
7}
21export function generateId(length): string {
22 const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
23 let textArray: string[] = [];
24
25 if (_.isUndefined(length)) {
26 length = 6;
27 }
28
29 for (let i = 0; i < length; i++) {
30 textArray.push(possible.charAt(Math.floor(Math.random() * possible.length)));
31 }
32
33 return textArray.join('');
34}

Related snippets