MersenneTwister, srand

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

MersenneTwister, srand

digxx
So what is the difference between srand and merseentwister?

when I do:

r=srand(0)

I get the same as 

r=MersenneTwister(0)

and also how do I get my random numbers

what do the different fields mean?
e.g.
julia> r.(1)
1-element Array{UInt32,1}:
 0x00000000


julia> r.(2)
Base.dSFMT.DSFMT_state(Int32[748398797,1073523691,-1738140313,1073664641,-1492392947,1073490074,-1625281839,1073254801,1875112882,1073717145  …  943540191,1073626624,1091647724,1073372234,-1273625233,-823628301,835224507,991807863,382,0])

julia> r.(2).(1)
770-element Array{Int32,1}:
   748398797
  1073523691
 -1738140313
  1073664641
 -1492392947
  1073490074
 -1625281839
  1073254801
  1875112882
  1073717145
  -147366646
  1073379643
  -822088544
  1073057897
     -172354
  1073036393
 -1801109415
  1073061557
 -1726958192
  1073632729
  -309172420
  1073464042
  -354763249
  1073128395
   135648219
  1073687628
    92195370
  1073342927
   -87798830
  1073300027
   446697077
  1073397042
 -1348144529
  1073439833
   -64993866
  1073659055
  -992725433
  1073226916
   348453421
  1072702220
           ⋮
  1073417805
 -1607069797
  1072770558
   118292460
  1073306270
  -572602520
  1073370707
  -445536129
  1073393538
  1989954253
  1073598613
   986054037
  1073137169
  1796020743
  1073612929
   161145485
  1073732406
  -773274735
  1072720842
  1219081491
  1073737258
  1793984938
  1072858519
 -1584606890
  1072715174
 -1892075178
  1073622009
  -183639381
  1072906897
   943540191
  1073626624
  1091647724
  1073372234
 -1273625233
  -823628301
   835224507
   991807863
         382
           0


julia> r.(3)
382-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 ⋮
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0


julia> r.(4)
382


The number I had in my head for MersenneTwister was 624 but I dont find it anywhere?
Do I only initialize the pseudo random number generator this way and the actual "random" number is then obtain by rand(1) for example?
How do I acutally set the seed coz when I do
srand(0) and rand() would actually be a mersennetwister I'd expect zeros everywhere...
Thx

Reply | Threaded
Open this post in threaded view
|

Re: MersenneTwister, srand

digxx
With number in my head I meant, that I expected to see random number arrays of size 624 since as far as I know they are created simultaneously,right?
Reply | Threaded
Open this post in threaded view
|

Re: MersenneTwister, srand

Isaiah Norton

On Fri, Oct 28, 2016 at 1:23 PM, digxx <[hidden email]> wrote:
With number in my head I meant, that I expected to see random number arrays of size 624 since as far as I know they are created simultaneously,right?

Reply | Threaded
Open this post in threaded view
|

Re: MersenneTwister, srand

digxx
Sorry but that doesn't answer my question. That's where I have the calling from but it does not explain the output and what it means...
Reply | Threaded
Open this post in threaded view
|

Re: MersenneTwister, srand

Isaiah Norton
So what is the difference between srand and merseentwister?

Per doc link, srand uses MT by default.

and also how do I get my random numbers

rand() for floats less than 1 by default, or specify a set to choose from:

help?> rand
search: rand randn rand! randn! randexp randperm randjump randexp! randcycle randsubseq randstring randsubseq! RandomDevice srand sprand sprandn sprandbool bitrand transcode

  rand([rng=GLOBAL_RNG], [S], [dims...])

  Pick a random element or array of random elements from the set of values specified by S; S can be

    •    an indexable collection (for example 1:n or ['x','y','z']), or

    •    a type: the set of values to pick from is then equivalent to typemin(S):typemax(S) for integers (this is not applicable to BigInt), and to [0, 1) for floating point numbers;

what do the different fields mean?

The fields aren't intended to be accessed, but you can see each element name with:

julia> fieldnames(MersenneTwister)
4-element Array{Symbol,1}:
 :seed
 :state
 :vals
 :idx

How do I acutally set the seed

srand
 
srand(0) and rand() would actually be a mersennetwister I'd expect zeros everywhere...

Why?  


On Fri, Oct 28, 2016 at 2:11 PM, digxx <[hidden email]> wrote:
Sorry but that doesn't answer my question. That's where I have the calling from but it does not explain the output and what it means...