【SICP练习】143 练习3.81
2015-09-08 00:00
393 查看
练习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柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.csdn.net/nomasp
相关文章推荐
- 异步流程控制:7 行代码学会 co 模块
- 重置默认样式 css reset第1/2页
- Oracle创建自增字段--ORACLE SEQUENCE的简单使用介绍
- 表单项的name命名为submit、reset引起的问题
- C#利用Random得随机数求均值、方差、正态分布的方法
- JavaScript原生对象之Number对象的属性和方法详解
- Prototype源码浅析 Number部分
- JS中不为人知的五种声明Number的方式简要概述
- JavaScript中的object转换成number或string规则介绍
- Javascript基础教程之数据类型 (数值 Number)
- JavaScript中number转换成string介绍
- Shell脚本实现随机数多种方法介绍(date、random、uuid)
- ERROR 1222 (21000): The used SELECT statements have a different number of columns
- Hibernate Oracle sequence的使用技巧
- 对于Form表单reset方法的新认识
- javascript parseInt与Number函数的区别
- Ajax loading gif generator
- PHP number_format() 函数定义和用法
- javascript Math.random()随机数函数
- Oracle中使用触发器(trigger)和序列(sequence)模拟实现自增列实例