10 examples of 'javascript random letter' in JavaScript

Every line of 'javascript random letter' 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
this disclaimer
86function getRandomChar(){
87 var randKey = round(random(65, 90));
88 char = String.fromCharCode(randKey);
89 char = char.toUpperCase();
90 return char;
91}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7function randomLetter(letter) {
8 var chars = 'abcdefghijklmnopqrstuvwxyz';
9 var i = Math.floor(Math.random() * chars.length);
10 var value = chars.substring(i, i + 1);
11
12 return isUpperCase(letter) ? value.toUpperCase() : value;
13}
87function getRandomLetter(letters) {
88 return letters.charAt(Math.floor(Math.random() * letters.length));
89}
19function randomString() {
20 const length = (Math.floor(Math.random() * 25) + 10);
21 let str = '';
22 for (let i = 0; i < length; i += 1) {
23 str += String.fromCharCode(Math.floor(Math.random() * 255))
24 }
25 return str;
26}
26function random() {
27 return Math.random().toString(36).substr(2);
28}
20export function getRandomChar(): string {
21 let n = Math.ceil(Math.random() * 100)
22 if (n <= 40) return String.fromCharCode(Math.floor(Math.random() * 26) + 65) // Majuscule
23 if (n <= 80) return String.fromCharCode(Math.floor(Math.random() * 26) + 97) // Minuscule
24 return String.fromCharCode(Math.floor(Math.random() * 10) + 48) // Numero
25}
42public static stringRandom(chars: number): string{
43 let text = "";
44 let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
45
46 for( let i = 0; i < chars; i++ )
47 text += possible.charAt(Math.floor(Math.random() * possible.length));
48
49 return text;
50}
122function random(length) {
123 var text = "";
124 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
125
126 for (var i = 0; i < length; i++) {
127 text += possible.charAt(Math.floor(Math.random() * possible.length));
128 }
129
130 return text;
131}
20function randomString() {
21 var text = "";
22 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
23
24 for (var i = 0; i < 2; i++)
25 text += possible.charAt(Math.floor(Math.random() * possible.length));
26
27 return text;
28}
29export function randomString () {
30 var string = ''
31 var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
32
33 for (var i = 0; i < 5; i++) { string += possible.charAt(Math.floor(Math.random() * possible.length)) }
34
35 return string
36}

Related snippets