← 수업 제작 도구
홈 › Advanced › Random Numbers

Random Numbers (무작위 숫자)

원본: Computation Layer 문서(Random Numbers)

영어 원문 단락 아래에 한국어 풀이를 두었다(번역이 아니라 해석이다). 코드 상자는 원문 그대로이고, 오른쪽 위의 Try It 버튼을 누르면 새 탭에서 그 화면의 번호별 코드 분석이 열린다.

Computation Layer supports random numbers. Random numbers are unique but stable for each student. This means that page reloads won't change the random numbers. However, every student will see a different set of random numbers. You can use this, for example, to give each student a different problem:

Computation Layer는 무작위 숫자를 지원한다. 무작위 숫자는 학생마다 고유하면서 안정적이다. 페이지를 새로 고쳐도 무작위 숫자가 바뀌지 않는다는 뜻이다. 하지만 모든 학생은 서로 다른 무작위 숫자 묶음을 본다. 이를 이용해 예를 들어 학생마다 다른 문제를 줄 수 있다:

Try It ↗
r = randomGenerator()
​
A = r.int(-12,-2)
B = r.int(3,7)
​
#evaluate C
C = numericValue(`${A}*${B}`)
​
#create a random equation 
#wrapped in backticks so that it will be rendered with CL
equation = `${A}x+${B}y=${C}`

In the above example, the numbers were created in the note component, but you can grab them off of the note's script keyword to, for example, evaluate correctness on the math input:

위 예에서는 메모 구성요소 안에서 숫자를 만들었지만, 메모의 script 키워드로 그 값을 가져와서 예를 들어 수식 답변의 정답 여부를 판정할 수 있다:

Try It ↗
correct: this.numericValue = note1.script.B

The randomGenerator can also take an argument, called a "seed." This lets you change which random numbers a student sees (e.g., hooking up a button to produce a series of random problems):

randomGenerator는 "씨앗(seed)"이라는 인자를 받을 수도 있다. 이렇게 하면 학생이 보는 무작위 숫자를 바꿀 수 있다(예: 버튼을 연결해 무작위 문제를 연속으로 만든다):

Try It ↗
r = randomGenerator(btn1.pressCount)
​
a = r.int(-20,20)
b = r.int(-20,20)
​
#beautiful prompt, taking into account the - in b if it's negative
prompt =
  when b >= 0 `${a}+${b}`
  otherwise `${a}${b}`

Here we can again evaluate correctness. This example makes use of the advanced patterns feature (see interpreting math) to ensure that students are typing in only a number:

여기서도 정답 여부를 판정할 수 있다. 이 예는 학생이 숫자만 입력했는지 확인하려고 고급 패턴 기능(interpreting math 참고)을 쓴다:

Try It ↗
disableEvaluation: true
isASimpleNumber = patterns.number.matches(this.latex)
​
correct: isASimpleNumber and this.numericValue = numericValue(`${prompt.script.a}+${prompt.script.b}`)
submitDisabled: not(isASimpleNumber)
​
resetOnChange: "${btn1.pressCount}"
​

Note that for many applications the random capabilities of the graphing calculator might be easier and more powerful! Random numbers in the calculator will behave similarly, remaining stable between page loads but different for different students.

많은 경우 그래핑 계산기의 무작위 기능이 더 쉽고 강력할 수 있다는 점에 유의한다! 계산기의 무작위 숫자도 비슷하게 페이지를 새로 고쳐도 그대로이고 학생마다 다르다.