시드는 바뀌는 출력을 재현 가능하게 만든다.
생성기는 비공개 시드 하나를 호출마다 바꾸면서도 같은 시작값에서는 같은 수열을 다시 만들 수 있습니다.
상태가 매번 바뀌는 생성기가 어떻게 정확히 같은 수열을 반복할 수 있을까요?
- Treat the current seed as one private mutable location
- Follow a recurrence from one generated value to the next
- Distinguish deterministic pseudorandomness from external randomness
- Reproduce a sequence by constructing a generator with the same seed
make-rand closes over seed. Each call multiplies the current value by 48271, takes the remainder modulo 2147483647, stores that result back in seed, and returns it. The next call therefore starts from the value produced by the previous call.
The recurrence is deterministic. Two separately constructed generators begin with private locations, but equal starting seeds make their value sequences equal. This small generator is useful for studying state and reproducibility, not for cryptography or security decisions.
(begin
(define (make-rand seed)
(lambda ()
(set! seed (remainder (* seed 48271) 2147483647))
seed))
(define rand (make-rand 1))
(list (rand) (rand) (rand) (rand) (rand)))- 출력
- —
- 값
- —
- 진단
- —
The first program returns (48271 182605794 1291394886 1914720637 2078669041). The second returns (337897 1278240558 337897 1278240558).
Find each set! of the captured seed and follow the stored result into the next call. In the second program, separate the two closure environments even though their first and second values match.
힌트를 보기 전에 프로그램을 바꿔 보세요.
Change only the right generator seed from 7 to 8. Predict which positions can still match before running the program.
힌트 하나 보기
The two generators have independent locations. Equal recurrences reproduce a sequence only when their starting seeds are equal.