Roger Hui wrote:
> The implementation can be refined to avoid
> proliferating the two verbs.  Thus:
> 
> init=: 4 : 0
>  sn=. 'state',x
>  y2=. 2{.y,9!:42 ''  NB. seed and optional RNG #
>  ('parm',x)=: y2
>  9!:43 {:y2          NB. select RNG
>  9!:1  {.y2          NB. set seed
>  (sn)=: 9!:44 ''     NB. record state
>  i.0 0
> )
> 
> gen=: 4 : 0
>  sn=. 'state',x
>  9!:45 ".sn          NB. set state
>  z=. [EMAIL PROTECTED]/y
>  (sn)=: 9!:44 ''     NB. record state
>  z
> )
> 

My personal taste prefer using coclass to organise verbs.
coclass 'rng'
create=: 3 : 0
y2=. 2{.y,9!:42 ''  NB. seed and optional RNG #
parm=: y2
9!:43 {:y2          NB. select RNG
9!:1 {.y2          NB. set seed
state=: 9!:44 ''     NB. record state
i.0 0
)

gen=: 4 : 0
9!:45 state          NB. set state
z=. x [EMAIL PROTECTED] y
state=: 9!:44 ''     NB. record state
z
)

roll=: 3 : 0
9!:45 state          NB. set state
z=. ? y
state=: 9!:44 ''     NB. record state
z
:
9!:45 state          NB. set state
z=. x ? y
state=: 9!:44 ''     NB. record state
z
)

destroy=: codestroy

NB. example
a=: 16807 conew 'rng'
b=: 314159 conew 'rng'
10 gen__a 1000
10 gen__b 1000
10 gen__a 1000
10 gen__b 1000
destroy__a ''
destroy__b ''

a=: 16807 conew 'rng'
b=: 314159 conew 'rng'
10 gen__a 1000
10 gen__a 1000
10 gen__b 1000
10 gen__b 1000
destroy__a ''
destroy__b ''


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

Reply via email to