zoukankan      html  css  js  c++  java
  • 【SICP练习】143 练习3.81

    练习3-81

    原文

    Exercise 3.81. Exercise 3.6 discussed generalizing the random-number generator to allow one to reset the random-number sequence so as to produce repeatable sequences of “random” numbers. Produce a stream formulation of this same generator that operates on an input stream of requests to generate a new random number or to reset the sequence to a specified value and that produces the desired stream of random numbers. Don’t use assignment in your solution.

    代码

    
    (define (random-update x)  
       (remainder (+ (* 13 x) 5) 24))
    ;Value: random-update
    
    (define random-init 
       (random-update (expt 2 32)))
    ;Value: random-init
    
    (define (random-number-generator command-stream) 
       (define random-number  
           (cons-stream random-init    
                        (stream-map (lambda (number command)            
                                    (cond    
                                     ((null? command) the-empty-stream)     
                                     ((eq? command 'generator)       
                                      (random-update number))    
                                    ((and (pair? command)              
                                          (eq? (car command) 'reset))    
                                     (cdr command))      
                                    (else     
                                     (error "bad command -- " command))))        
                                    random-number        
                                    command-stream))) 
           random-number)
     ;Value: random-number-generator
    



    感谢您的访问,希望对您有所帮助。 欢迎大家关注或收藏、评论或点赞。


    为使本文得到斧正和提问,转载请注明出处:
    http://blog.csdn.net/nomasp


    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    js验证邮箱
    输出一个金字塔
    仿QQ聊天软件2.0版
    zoj 3662 第37届ACM/ICPC长春赛区H题(DP)
    zoj 3659 第37届ACM/ICPC 长春赛区现场赛E题 (并查集)
    zoj 3640 概率dp
    hdu 5203 && BC Round #37 1002
    poj 3071 概率dp
    poj 2151 概率dp
    zoj 3460 二分+二分图匹配
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786057.html
Copyright © 2011-2022 走看看