File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
1-js/05-data-types/02-number/8-random-min-max Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 1
- We need to "map" all values from the interval 0..1 into values from ` min ` to ` max ` .
1
+ 0..1 ꡬκ°μ λͺ¨λ κ°μ ` min ` μμ ` max ` κΉμ§μ κ°μΌλ‘ 'λ§€ν' ν΄μΌ ν©λλ€ .
2
2
3
- That can be done in two stages :
3
+ λ€μ λ¨κ³λ‘ μνν μ μμ΅λλ€ :
4
4
5
- 1 . If we multiply a random number from 0..1 by ` max-min ` , then the interval of possible values increases ` 0..1 ` to ` 0..max-min ` .
6
- 2 . Now if we add ` min ` , the possible interval becomes from ` min ` to ` max ` .
5
+ 1 . 0..1 ꡬκ°μ λμμ ` max-min ` μ κ³±νλ©΄, κ°λ₯ν κ°μ ꡬκ°μ΄ ` 0..1 ` μμ ` 0..max-min ` μΌλ‘ μ¦κ°ν©λλ€ .
6
+ 2 . μ΄μ ` min ` μ λνλ©΄, κ°λ₯ν κ°μ ꡬκ°μ ` min ` μμ ` max ` κΉμ§κ° λ©λλ€ .
7
7
8
- The function :
8
+ μμ :
9
9
10
10
``` js run
11
11
function random (min , max ) {
12
12
return min + Math .random () * (max - min);
13
13
}
14
14
15
15
alert ( random (1 , 5 ) );
16
- alert ( random (1 , 5 ) );
16
+ alert ( random (1 , 5 ) );
17
17
alert ( random (1 , 5 ) );
18
18
```
19
19
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ importance: 2
2
2
3
3
---
4
4
5
- # A random number from min to max
5
+ # μ΅μκ°μμ μ΅λκ°κΉμ§μ λμ
6
6
7
- The built-in function ` Math.random() ` creates a random value from ` 0 ` to ` 1 ` (not including ` 1 ` ).
7
+ λ΄μ₯ ν¨μ ` Math.random() ` μ ` 0 ` μμ ` 1 ` κΉμ§μ λμλ₯Ό μμ±ν©λλ€( ` 1 ` μ μ μΈ ).
8
8
9
- Write the function ` random( min, max) ` to generate a random floating-point number from ` min ` to ` max ` (not including ` max ` ).
9
+ ` min ` μμ ` max ` κΉμ§ 무μμμ λΆλμμμ μ«μλ₯Ό μμ±νλ ν¨μ ` random( min, max) ` μ μμ±ν΄ 보μΈμ( ` max ` λ μ μΈ ).
10
10
11
- Examples of its work :
11
+ μμ :
12
12
13
13
``` js
14
14
alert ( random (1 , 5 ) ); // 1.2345623452
You canβt perform that action at this time.
0 commit comments