Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 1-js/05-data-types/02-number/8-random-min-max/solution.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
We need to "map" all values from the interval 0..1 into values from `min` to `max`.
0..1 κ΅¬κ°„μ˜ λͺ¨λ“  값을 `min`μ—μ„œ `max`κΉŒμ§€μ˜ κ°’μœΌλ‘œ 'λ§€ν•‘' ν•΄μ•Ό ν•©λ‹ˆλ‹€.

That can be done in two stages:
맀핑은 두 λ‹¨κ³„λ‘œ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

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`.
2. Now if we add `min`, the possible interval becomes from `min` to `max`.
1. 0..1 κ΅¬κ°„μ˜ λ‚œμˆ˜μ— `max-min`을 κ³±ν•˜λ©΄, κ°€λŠ₯ν•œ κ°’μ˜ ꡬ간이 `0..1`μ—μ„œ `0..max-min`으둜 μ¦κ°€ν•©λ‹ˆλ‹€.
2. 이제 `min`을 λ”ν•˜λ©΄, κ°€λŠ₯ν•œ κ°’μ˜ ꡬ간은 `min`μ—μ„œ `max`κΉŒμ§€κ°€ λ©λ‹ˆλ‹€.

The function:
μ˜ˆμ‹œ:

```js run
function random(min, max) {
return min + Math.random() * (max - min);
}

alert( random(1, 5) );
alert( random(1, 5) );
alert( random(1, 5) );
alert( random(1, 5) );
```

8 changes: 4 additions & 4 deletions 1-js/05-data-types/02-number/8-random-min-max/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 2

---

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

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

Write the function `random(min, max)` to generate a random floating-point number from `min` to `max` (not including `max`).
`min`μ—μ„œ `max`κΉŒμ§€ λ¬΄μž‘μœ„μ˜ λΆ€λ™μ†Œμˆ˜μ  숫자λ₯Ό μƒμ„±ν•˜λŠ” ν•¨μˆ˜ `random(min, max)`을 μž‘μ„±ν•΄ λ³΄μ„Έμš”(`max`λŠ” μ œμ™Έ).

Examples of its work:
μ˜ˆμ‹œ:

```js
alert( random(1, 5) ); // 1.2345623452
Expand Down