简体   繁体   中英

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 ?

    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).

Create an implicit RandBasis and thread that through to wherever you create random generators. I should probably improve the API for this, but something like:

implicit val randBasis: RandBasis = new RandBasis(new ThreadLocalRandomGenerator(new MersenneTwister(seed)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM