Currently, if I want to parallelize my independent computations (e.g. 10 monte carlo paths), on each subprocess, I initialize an RNG, rng = Random.MersenneTwister(process_number)
, and then generate a random number using e.g. randn(rng)
. But I can't seem able to feed this rng
object if I were to use a distribution object from Distributions.jl.
import Distributions
var = rand(Distributions.Uniform(1.0, 20.0))
Is there a way to feed in the rng
object into the code above?
You can pass the rng as the first argument to rand
as usual, I think?
julia> using Distributions, Random
julia> rand(MersenneTwister(1234), Uniform(1.0, 20.0))
12.226048134648494
julia> rand(MersenneTwister(1234), Uniform(1.0, 20.0))
12.226048134648494
That solves it, thank you very much!
Last updated: Nov 06 2024 at 04:40 UTC