Last active
November 22, 2016 16:17
-
-
Save zhouqiang-cl/1559760778c7654b444d7d931cbacfdc to your computer and use it in GitHub Desktop.
common lisp 的随机数生成函数 RANDOM 及随机状态变量 *RANDOM-STATE*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
语法 | |
random limit &optional random-state => random-number | |
make-random-state &optional state => new-state | |
参数和值 | |
limit --- 一个正整数或者一个正的浮点数 | |
random-state --- 随机状态, 默认为当前的随机状态 | |
描述 | |
random 生成一个随机数. random-state 如果相同,limit 不变的情况下, 会生成同样的随机数 | |
*random-state* 包含伪随机生成器的状态的 | |
make-random-state 产生一个random-state | |
代码 | |
* (random 100) | |
92 | |
* (random 10.5 ) | |
2.845016 | |
---(在这之前需要对 snap-shot 定义)--- | |
* (let ((*random-state* snap-shot)) | |
(loop for i from 1 to 10 collect (random 100))) | |
(24 89 92 59 92 13 49 46 7 45) | |
* (loop for i from 1 to 10 collect (random 100)) | |
(24 89 92 59 92 13 49 46 7 45) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment