[英]How to initialize a specific random seed in scala breeze, say for Gaussian distribution?
How do I force the random number generator (if possible) with a specific seed in scala breeze, so say the following scala code always generate the same sequence seq
? 如何使用scala breeze中的特定种子强制随机数生成器(如果可能),所以说下面的scala代码总是生成相同的序列seq
?
import breeze.stats.distributions._
val g = new Gaussian(0, 1)
val seq = gau.sample(3)
I'm using scala to build a monte carlo simulator, and would like the simulation results to be repeatable (through parameterization of a specific random seed). 我正在使用scala构建蒙特卡罗模拟器,并希望模拟结果可重复(通过特定随机种子的参数化)。
Create an implicit RandBasis and thread that through to wherever you create random generators. 创建一个隐式RandBasis并将其线程连接到创建随机生成器的任何位置。 I should probably improve the API for this, but something like: 我应该为此改进API,但是类似于:
implicit val randBasis: RandBasis = new RandBasis(new ThreadLocalRandomGenerator(new MersenneTwister(seed)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.