(Random) in Common Lisp Not So Random?

眉间皱痕 提交于 2019-12-04 23:28:24
kennytm

You need to seed the random state at the start of the program.

(setf *random-state* (make-random-state t))
;; # this initializes the global random state by
;;   "some means" (e.g. current time.)

I think that if you define a function with a random number in it, it is not called when you call the function, actually, it will be determined when you load in the file and when it runs this definition it is fixed to that value. Then you are calling the function each time, the number will always be the same. When I passed in a variable to the function with a random each time it was called, then it was random each time. At least, that what I experienced in my program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!