【发布时间】:2016-11-29 02:25:28
【问题描述】:
Structure and Interpretation of Computer Programs提出的fermat-test过程有一个theta-of-log(n)的增长顺序,我和很多人的实验已经验证了这一点。
让我感到困惑的是其定义中的random 原始过程。这是否意味着random 的增长顺序最多是 log(n) 的 theta?经过一番搜索,我仍然不确定是否可以编写一个增长顺序不超过 log(n) 的 theta 的伪随机数生成器。
代码如下:
(define (fermat-test n)
(define (try-it a)
(= (expmod a n n) a))
; Wait a second! What's the order of growth of `random`?
(try-it (+ 1 (random (- n 1)))))
,其中expmod 的增长顺序为 theta-of-log(n):
(define (expmod base exp m)
(cond ((= exp 0) 1)
((even? exp)
(remainder (square (expmod base (/ exp 2) m))
m))
(else
(remainder (* base (expmod base (- exp 1) m))
m))))
你能给我解释一下吗?
- 如果确实存在这样的伪随机数生成器,请告诉我它是如何工作的。
- 如果不存在这样的伪随机数生成器,请告诉我
fermat-test如何仍然具有 theta-of-log(n) 增长顺序。
【问题讨论】:
标签: algorithm random scheme time-complexity sicp