How about this for a simple unoptimized solution:
 
dice2=: 9999&$: : (4 : 0)"0
  d=. x (>[EMAIL PROTECTED] # [) y
  while. y <: z=. (#.?) d do. end.
  z
)

   list +/"[EMAIL PROTECTED] 10 dice2 1e4#13
700 809 795 753 776 790 808 785 795 712 773 735 769 
   list +/"[EMAIL PROTECTED] 10 dice 1e4#13
784 792 742 759 776 768 769 762 775 744 784 810 735 

 
 
JavaScript and Java do have a goto statement,
it's just called differently to fit with the structural model.
That explains it why your JavaScirpt programs look
so nicely readable and unobfuscated--you just haven't
discovered it.


----- Original Message ----
From: Andrew Nikitin <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, July 13, 2006 5:30:32 PM
Subject: [Jbeta] monadic '?' (and #. slowdown


R&S HUI:
>That is, "dice" does not generate n random digits.
>What it does is it generates random digits one
>by one, and depending on the digit d:
>
>d<i{y - keep it, and generate n-1-i more digits
>         without further checking
We can do this because at this point we know for sure that r
will be less than y no matter what the other digits are.

>d=i{y - increment i and generate the next digit
That's where the whole suspence is coming from. Depending on
the following digits r can be less or greater than y and we
need to keep watching for it.

>d>i{y - discard all digits and start from scratch
we do this because at this point we already know r  y and
we need to discard entire r. There is no need to generate
rest of the digits because of the assumption of idependence.

>As well, if we "tweak" the verb and omit the
>"discard all digits" part but instead just
>discard the current digit d and generate
>another digit d1 and check again
>satisfy your description of "uniform finite average number of discards".  
>But you must have
>a reason for not doing that,

In this case digits will not be uniformly distributed beween
0 and x-1, instead each digit will be uniformly distributed
between 0 and y[i] and resulting y will not be uniformly
distributed -- and that's my reason: I need uniformly
distributed y.

>otherwise you would
>have (I guess) gotten rid of the distasteful goto.

There is nothing distasteful in carefully and
appropriately placed goto.
BTW, I want to take opportunity to thank you for not
abolishing goto like those Java and Javascript people did.
I just wish it was less ugly looking. More like original 
would be better. Also, because label name is part of a keyword, vim command 
'*' (search  identifier under cursor) does not take to the right place.


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

Reply via email to