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