如何每次从重复功能获得不同的值?

THX*_*137 2 clojure clojurescript

我每次得到10个相同的结果:

(repeat 10 (rand 10))
Run Code Online (Sandbox Code Playgroud)

例如:

=> (2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718 2.54681114871718)
Run Code Online (Sandbox Code Playgroud)

我假设它是某种记忆,我是对的吗?我每次如何获得不同的价值?

Lee*_*Lee 11

repeat返回包含给定值的序列,因此(rand 10)作为参数计算一次.你可以使用repeatedly哪个功能:

(repeatedly 10 #(rand 10))
Run Code Online (Sandbox Code Playgroud)