Skip to content

Commit 88924f6

Browse files
[κ³Όμ œλ²ˆμ—­] Part1 5.2 μˆ«μžν˜• 8-random-min-max
1 parent 31d5a0c commit 88924f6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
We need to "map" all values from the interval 0..1 into values from `min` to `max`.
1+
0..1 κ΅¬κ°„μ˜ λͺ¨λ“  값을 `min`μ—μ„œ `max`κΉŒμ§€μ˜ κ°’μœΌλ‘œ 'λ§€ν•‘' ν•΄μ•Ό ν•©λ‹ˆλ‹€.
22

3-
That can be done in two stages:
3+
λ‹€μŒ λ‹¨κ³„λ‘œ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€:
44

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`κΉŒμ§€κ°€ λ©λ‹ˆλ‹€.
77

8-
The function:
8+
μ˜ˆμ‹œ:
99

1010
```js run
1111
function random(min, max) {
1212
return min + Math.random() * (max - min);
1313
}
1414

1515
alert( random(1, 5) );
16-
alert( random(1, 5) );
16+
alert( random(1, 5) );
1717
alert( random(1, 5) );
1818
```
1919

β€Ž1-js/05-data-types/02-number/8-random-min-max/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 2
22

33
---
44

5-
# A random number from min to max
5+
# μ΅œμ†Ÿκ°’μ—μ„œ μ΅œλŒ“κ°’κΉŒμ§€μ˜ λ‚œμˆ˜
66

7-
The built-in function `Math.random()` creates a random value from `0` to `1` (not including `1`).
7+
λ‚΄μž₯ ν•¨μˆ˜ `Math.random()`은 `0`μ—μ„œ `1`κΉŒμ§€μ˜ λ‚œμˆ˜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€(`1`은 μ œμ™Έ).
88

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`λŠ” μ œμ™Έ).
1010

11-
Examples of its work:
11+
μ˜ˆμ‹œ:
1212

1313
```js
1414
alert( random(1, 5) ); // 1.2345623452

0 commit comments

Comments
 (0)