-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27RandomNum.js
52 lines (38 loc) · 977 Bytes
/
27RandomNum.js
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
/* Generate random from k to n */
// let n = 10;
// let res = Math.floor(Math.random() * n) + 1;
// console.log(res);
/* Between 20 to 25*/
// let random = Math.floor(Math.random() * 5) + 20;
// console.log(random);
/* Start and end */
// let from = 50;
// let to = 100;
// let res = Math.floor(Math.random() * (to - from +1 )) + from;
// console.log(res);
/* roll dice */
// let dice = Math.floor(Math.random()*6) +1;
// console.log(dice);
/* loop,random() */
// let from = 50;
// let to = 100;
// let res;
// while ((res = Math.floor(Math.random() * (to - from + 1)) + from) !== 66) {
// console.log(res);
// }
// console.log(res);
// console.log("Number 66 is generated!");
/* loop,random(),counter */
let from = 25;
let to = 70;
let res;
let attempt = 0;
while (true) {
attempt++;
res = Math.floor(Math.random() * (to - from + 1)) + from;
console.log(res);
if (res === 66) {
console.log("66 found at " + attempt + " attempts");
break;
}
}