JuliaSIMD / VectorizedRNG.jl

Vectorized uniform and normal random samplers.
MIT License
33 stars 7 forks source link

Any way to control the seed? #2

Closed rcalxrc08 closed 4 years ago

rcalxrc08 commented 4 years ago

I can't find a proper way to specify the seed of the parallel rng. Is it possible?

chriselrod commented 4 years ago

I'll add support for that.

chriselrod commented 4 years ago
julia> using VectorizedRNG

julia> rand(local_rng(), 30)'
1×30 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 0.787765  0.187013  0.646974  0.965822  0.58504  0.592439  0.259422  0.711535  0.465474  …  0.171145  0.990088  0.338733  0.880647  0.122954  0.407847  0.587394  0.335888  0.996064

julia> VectorizedRNG.seed!(1)

julia> rand(local_rng(), 30)'
1×30 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 0.371016  0.804553  0.243923  0.261726  0.875966  0.942672  0.875786  0.0255004  0.236359  …  0.628247  0.814513  0.924231  0.398405  0.604068  0.915064  0.984332  0.773448  0.325699

julia> rand(local_rng(), 30)'
1×30 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 0.0768554  0.841872  0.721168  0.272423  0.282721  0.351876  0.0552785  0.251814  0.548307  …  0.235919  0.953537  0.0733153  0.867094  0.401489  0.286259  0.603014  0.627845  0.193328

julia> VectorizedRNG.seed!(1)

julia> rand(local_rng(), 30)'
1×30 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 0.371016  0.804553  0.243923  0.261726  0.875966  0.942672  0.875786  0.0255004  0.236359  …  0.628247  0.814513  0.924231  0.398405  0.604068  0.915064  0.984332  0.773448  0.325699

julia> rand(local_rng(), 30)'
1×30 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 0.0768554  0.841872  0.721168  0.272423  0.282721  0.351876  0.0552785  0.251814  0.548307  …  0.235919  0.953537  0.0733153  0.867094  0.401489  0.286259  0.603014  0.627845  0.193328
chriselrod commented 4 years ago

Note that the streams will not be identical across different CPUs.