-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.generation.js
More file actions
64 lines (48 loc) · 1.49 KB
/
random.generation.js
File metadata and controls
64 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//RANDOM GENERATION
//RANDOM NUMBER
//floating point number between 0 and 1
let randomNumber= Math.random();
console.log(randomNumber)
//intergers within a specific range
let min=1;
let max = 10;
let randomInt = Math.floor(Math.random()*(max-min +1))+min
console.log(randomInt)
//RANDOM BOOLEANS
let randomBoolean = Math.random() >= 0.5;
console.log(randomBoolean)
//RANDOM STRINGS
function randomString(length){
let characters = 'ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstuvxyz0123456789';
let result='';
for(let i=0;i<length;i++){
result += characters.charAt(Math.floor(Math.random()* characters.length))
}
return result;
}
console.log(randomString(10))
//RANDOM ARRAY ELEMENT
let array = [1,2,3,4,5]
let randomElement = array[Math.floor(Math.random()* array.length)];
console.log(randomElement)
//RANDOM COLOR GENERATION
function randomColor(){
let r = Math.floor(Math.random()*256);
let g = Math.floor(Math.random()*256);
let b = Math.floor(Math.random()*256);
return `rgb(${r},${g},${b})`;
}
console.log(randomColor())
//RANDOM PASSWORD GNERATEION
function randomPassword(length){
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+';
let result ='';
for(let i=0; i <length;i ++){
result += characters.charAt(Math.floor(Math.random()* characters.length));
}
return result;
}
console.log(randomPassword(12));
console.log("out")
console.log("hellow")
console.log("this is a code ")