Help!  For you email skimmers please jump to the agenda version mystery.

Control the RNG:

Under system global parameters, you can choose the random number generator and state.
http://www.jsoftware.com/docs/help701/dictionary/dx009.htm
starting from 9!:42 .


Power version:

Here's a working tacit version using power. This roll always uses a six sided die.

   While =: conjunction def 'u^:v^:_'

   roll =: >:@:?@:6:
   game =: [: }. (, roll)While(6={:)

   game&> 36#6   NB. play the game 36 times


Agenda version:
Where does roll go? Again, always with a 6 sided die, rolling the die needs to be an argument to the self reference. Thus $:@roll or as the fork ([: $: roll)

   roll =: >:@:?@:6:
   g=:[`(, ([: $: roll))@.(6 = {:)
   0 1 }. g">36#6  NB. play 36 games.

Mystery, if I replace behead for same in 0 { the_gerund, I get curtailing rather than beheading.

   g_behead=: }.`(, ([: $: roll))@.(6 = {:)

   g_behead">5#6
6 0
6 6
6 0
6 0
6 6

Date: Thu, 25 Sep 2014 09:06:17 -0400
From: Johann Hibschman<[email protected]>
To: Programming forum<[email protected]>
Subject: [Jprogramming] Repeated rolling dice
Message-ID:
        <cae3jda-s35jhr8kqjo-kh-gcgp5drpetann9pvcdfnhusxk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi all,

For fun, I've been running some statistics for a game with an unusual
rule for rolling dice: if a 6 is rolled, roll again and add the
result, repeating on any subsequent 6s. I wanted to implement this in
J, collecting all the individual rolls (rather than just the sum.)

It seems like there should be a more clever and elegant way to do
this, but this is what I have:

NB. Simple roll.
roll0 =: >:@?

NB. This seems to work, but it's not very clever.
roll =: 3 : 0
   r =. >:?y
   if. r=y do. r=. r,(roll y) end.
   r
)

NB. Attempt at iterating via power.  Fails because repeats
NB. signal termination.
roll0^:(6&=)^:(<_) 6

NB. Attempt at iterating via agenda.  Not even close yet.
NB. ]`(]+$:) @. (=&6)  NB. where to stick in the roll?

This gives what I expect:

    roll"0 ] 10#6
6 1 0
3 0 0
3 0 0
2 0 0
5 0 0
2 0 0
6 6 2
2 0 0
1 0 0
6 3 0

But is there a better way to do this? Also, are there any known issues
with the RNG? I've not gathered enough statistics to prove it, but the
results look clumpier (more identical values in a row) than I expect.
Now, I know that's a common cognitive bias, so it may just be me, but
is there a discussion of the quality of the RNG somewhere?

Thanks,
Johann


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

Reply via email to