Skip to content

Commit 87f4da5

Browse files
[과제번역] Part1 5.2 숫자형 9-random-int-min-max
1 parent 31d5a0c commit 87f4da5

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# The simple but wrong solution
1+
# 간단하지만 틀린 해답
22

3-
The simplest, but wrong solution would be to generate a value from `min` to `max` and round it:
3+
가장 간단하지만 틀린 해답은 `min`에서 `max`까지의 값을 생성하고 반올림하는 것입니다.
44

55
```js run
66
function randomInteger(min, max) {
@@ -11,28 +11,28 @@ function randomInteger(min, max) {
1111
alert( randomInteger(1, 3) );
1212
```
1313

14-
The function works, but it is incorrect. The probability to get edge values `min` and `max` is two times less than any other.
14+
`randomInteger` 함수는 동작하지만, 올바르지 않습니다. 에지값 `min``max`가 나올 확률이 두 배 적습니다.
1515

16-
If you run the example above many times, you would easily see that `2` appears the most often.
16+
위의 예시를 여러 번 실행하면, `2`가 가장 많이 나타나는 것을 알 수 있습니다.
1717

18-
That happens because `Math.round()` gets random numbers from the interval `1..3` and rounds them as follows:
18+
`Math.round()``1..3` 구간에서 난수를 가져와 다음과 같이 반올림하기 때문입니다.
1919

2020
```js no-beautify
21-
values from 1 ... to 1.4999999999 become 1
22-
values from 1.5 ... to 2.4999999999 become 2
23-
values from 2.5 ... to 2.9999999999 become 3
21+
1 에서 ... 1.4999999999 까지의 값은 1 이 됩니다.
22+
1.5 에서 ... 2.4999999999 까지의 값은 2 가 됩니다.
23+
2.5 에서 ... 2.9999999999 까지의 값은 3 이 됩니다.
2424
```
2525

26-
Now we can clearly see that `1` gets twice less values than `2`. And the same with `3`.
26+
이제 `1``2`보다 두 배 적게 나오는 것을 알 수 있습니다. `3`도 마찬가지입니다.
2727

28-
# The correct solution
28+
# 올바른 해답
2929

30-
There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 3.5`, thus adding the required probabilities to the edges:
30+
올바른 해답이 많이 있지만 그중 하나는 구간을 조정하는 것입니다. 동일한 간격을 보장하기 위해서, `0.5 에서 3.5` 사이의 값을 생성하여, 에지값에 필요한 확률을 추가할 수 있습니다.
3131

3232
```js run
3333
*!*
3434
function randomInteger(min, max) {
35-
// now rand is from (min-0.5) to (max+0.5)
35+
// rand는 (min-0.5)에서 (max+0.5)까지 입니다.
3636
let rand = min - 0.5 + Math.random() * (max - min + 1);
3737
return Math.round(rand);
3838
}
@@ -41,12 +41,12 @@ function randomInteger(min, max) {
4141
alert( randomInteger(1, 3) );
4242
```
4343

44-
An alternative way could be to use `Math.floor` for a random number from `min` to `max+1`:
44+
다른 방법은 `min`에서 `max+1`까지의 난수에 `Math.floor`를 사용하는 것입니다.
4545

4646
```js run
4747
*!*
4848
function randomInteger(min, max) {
49-
// here rand is from min to (max+1)
49+
// rand는 min에서 (max+1)까지 입니다.
5050
let rand = min + Math.random() * (max + 1 - min);
5151
return Math.floor(rand);
5252
}
@@ -55,12 +55,12 @@ function randomInteger(min, max) {
5555
alert( randomInteger(1, 3) );
5656
```
5757

58-
Now all intervals are mapped this way:
58+
모든 구간이 다음과 같이 매핑되었습니다.
5959

6060
```js no-beautify
61-
values from 1 ... to 1.9999999999 become 1
62-
values from 2 ... to 2.9999999999 become 2
63-
values from 3 ... to 3.9999999999 become 3
61+
1 ... 에서 1.9999999999 까지의 값은 1 이 됩니다.
62+
2 ... 에서 2.9999999999 까지의 값은 2 가 됩니다.
63+
3 ... 에서 3.9999999999 까지의 값은 3 이 됩니다.
6464
```
6565

66-
All intervals have the same length, making the final distribution uniform.
66+
모든 구간은 같은 길이를 가지고 있고, 최종 분포도 균일합니다.

1-js/05-data-types/02-number/9-random-int-min-max/task.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ importance: 2
22

33
---
44

5-
# A random integer from min to max
5+
# 최솟값에서 최대값까지의 무작위 정수
66

7-
Create a function `randomInteger(min, max)` that generates a random *integer* number from `min` to `max` including both `min` and `max` as possible values.
7+
가능한 값으로 `min``max`을 포함하여 `min`에서 `max`까지 무작위 *정수*를 생성하는 함수 `randomInteger(min, max)`을 작성해 보세요.
88

9-
Any number from the interval `min..max` must appear with the same probability.
9+
`min..max` 구간의 어떤 숫자라도 같은 확률로 나타나야 합니다.
1010

1111

12-
Examples of its work:
12+
예시:
1313

1414
```js
1515
alert( randomInteger(1, 5) ); // 1
1616
alert( randomInteger(1, 5) ); // 3
1717
alert( randomInteger(1, 5) ); // 5
1818
```
1919

20-
You can use the solution of the [previous task](info:task/random-min-max) as the base.
20+
[이전 과제](info:task/random-min-max)의 해답을 바탕으로 사용할 수 있습니다.

0 commit comments

Comments
 (0)