You can do

julia> srand(123)
julia> rand(3)
3-element Array{Float64,1}:
 0.768448
 0.940515
 0.673959

julia> srand(123)
julia> rand(3)
3-element Array{Float64,1}:
 0.768448
 0.940515
 0.673959

but it appears that something is wrong when using an RNG object.

2014-04-17 19:18 GMT+02:00 X Du <[email protected]>:
>
>
> Thanks Isaiah,
>
>  It seems that srand([rng], seed) does not work, I always got the error
rng is not defined.
> I tried to set MersenneTwister([2]) and use rand(rng::AbstractRNG[,
dims...]) to generate the random number. It did not work.
>
> Could you please give me an example? Many thanks in advance.
>
> Isaac
>
>
>
> On Thursday, April 17, 2014 12:45:01 PM UTC+2, X Du wrote:
>>
>>
>>  Hi All,
>>
>>  Is there some comments to save or load a particular state when
generating rand numbers?
>> e.g. the code in Matlab:
>>
>> stream = RandStream.getGlobalStream;
>> savedState = stream.State;
>> u1 = rand(1,5)
>> u1 =
>>     0.8147    0.9058    0.1270    0.9134    0.6324
>>
>> stream.State = savedState;
>> u2 = rand(1,5)
>> u2 =
>>     0.8147    0.9058    0.1270    0.9134    0.6324
>>
>> which can produce exactly the same random numbers.
>>
>>
>> Thanks!
>>
>> Isaac
>>
>>
>>



--
Med venlig hilsen

Andreas Noack Jensen

Reply via email to