A quick scan of the J source reveals that each of
the RNGs 1-4 uses different code for 32-bit vs.
64-bit (and consequently so does RNG-0).
Therefore, 128!:4 will give different answers 
on J32 and J64.

I do have a model in J of Knuth's GB_Flip (RNG-1)
in the J test scripts.  I append it below in case you 
may find it useful.  No guarantees.  Performance is 
probably not good.


NB. Model of gb_flip ----------------------------------------------------

mod_diff=: (<._1+2^31)&(17 b.)@:- 

gb_next_rand=: 3 : 0
 if. 0 > gb_i do. gb_i=: <: # gb_A=: gb_flip_cycle gb_A end.
 (gb_i=: <:gb_i) ] gb_i{gb_A
)

gb_flip_cycle=: 3 : 0
 +/ (0 1 2=/<.(i.55)%24) * (mod_diff 31&|.)^:1 2 3~y
)

gb_init_rand1=: 3 : 0
 prev=. s=. y mod_diff 0  NB. strip off the sign
 seed=. (31$2) #: s
 next=. 1
 z=. ''
 for. i.54 do.
  z=. z,next
  t=. next
  seed=. _1 |. seed        NB. cyclic shift right 1
  next=. (prev mod_diff next) mod_diff #. seed
  prev=. t
 end.
 s,~z /: 55|+/\54$21
)

gb_init_rand=: 3 : 0
 0 0 $ gb_i=: _2 + # gb_A=: gb_flip_cycle^:5 gb_init_rand1 y
)

roll=: 3 : 0
 assert. 0~:y
 z=. i.0
 for_t. y (] - |) <.2^31 do.
  while. t<:r=. gb_next_rand '' do. end.
  z=. z,r
 end.
 ($y)$y|z
)

roll0=: 3 : 0
 assert. 0=y
 (2^53) %~ (2^31) #. |."1 (0 2^22)|"1 gb_next_rand"0 (($y),2)$0
)

gb_init_rand _314159
119318998 -: gb_next_rand ''
1 [ gb_next_rand^:133 ''
748103812 -: roll 16#.8#5



----- Original Message -----
From: Ewart Shaw <[email protected]>
Date: Friday, October 14, 2011 4:10
Subject: [Jprogramming] 32- & 64-bit PRNGs
To: [email protected]

> Dear forum,
> 
> I want to generate pseudorandom sequences that are the same for 
> 32- & 64-bit J.
> I need better statistical properties than the old linear 
> congruential generator
> as in 'roll' & 'deal' at   
> http://www.jsoftware.com/help/release/random.htm .
> 
> I could implement the 32-bit MT19937 'by hand' in J via the 
> pseudocode at
>    http://en.wikipedia.org/wiki/Mersenne_twister
> but prefer if possible not to reinvent the wheel.
> 
> Is it possible (for example) to convert the output from  
> 128!:4  in J64 to what
> it would have been from the same seeds in J32, for any of the 
> current PRNGs?
> 
> Many thanks for any suggestions -- Ewart Shaw

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to