10 examples of 'random name generator javascript' in JavaScript

Every line of 'random name 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
15function randomName() {
16 let text = '';
17 const possible = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
18 'abcdefghijklmnopqrstuvwxyz0123456789');
19
20 for (let i = 0; i < 5; i++) {
21 text += possible.charAt(Math.floor(Math.random()
22 * possible.length));
23 }
24 return text;
25}
15function randomName(): string {
16 let name = "";
17 for (let i = 0; i < 10; i++) {
18 name += CHARS[Math.floor(Math.random() * CHARS.length)];
19 }
20 return name;
21}
91function randomName() {
92 var firstName = ['Jack', 'Peter', 'Frank', 'Steven'];
93 var surname = ['White', 'Jackson', 'Sinatra', 'Spielberg'];
94 return firstName[Math.floor(Math.random() * 4)] + " " + surname[Math.floor(Math.random() * 4)];
95}
67getName () {
68 return Random.faker.name.findName();
69}
659function getRandomName() {
660 return names[Math.floor(Math.random() * numNames)];
661}
47export default function nameGenerator() {
48 function f() {
49 const adj = sample(adjectives);
50 const noun = sample(nouns);
51 return adj + ' ' + noun;
52 }
53
54 const max_len = 20;
55
56 let s = f();
57 while (s.length > max_len) {
58 s = f();
59 }
60 return s;
61}
116function randomname() {
117 return 'tmp' + (+new Date);
118}
12public static generate(prefix: string, randomLength: number): string {
13 const possibleCharacters: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
14 const possibleCharactersLength: number = possibleCharacters.length;
15 let randomPart: string = '';
16
17 for (let i = 0; i < randomLength; i++) {
18 let currentRandomIndex: number = Math.floor(Math.random() * Math.floor(possibleCharactersLength));
19
20 randomPart += possibleCharacters[currentRandomIndex];
21 }
22
23 return prefix + randomPart;
24}
3export default function createRandomName(): string {
4 return `RSI-${Math.random()
5 .toString(36)
6 .substr(2, 9)}`;
7}
70generate(force = false) {
71 const { gender, theme } = this;
72 const { result } = roll.roll('1d2');
73
74 // get from the names pool if a number of conditions are met
75 if (
76 ((result === 1) || force) &&
77 (Object.keys(this.names).length > 0)
78 ) {
79 return this.getNameFromNames();
80 }
81
82 return this.nomina.generate({ type: gender, theme });
83}

Related snippets