Roger Hui wrote:
> 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
> d=i{y - increment i and generate the next digit
> d>i{y - discard all digits and start from scratch
For example, if x is 10, and y is 1234, the first
digit is picked randomly from the set 0 1, with
even odds. If the digit picked is 0, then the
rest of the digits are randomly picked in the
range 0..9.
If the digit is 1, then the next digit is picked
randomly from the set 0 1 2 3 4 5 6 7 8 9. If
it's 0 or 1, the remaining digits are fine. If
it's 2, the remaining digits still need to be
tested. If it's greater than 2, the number is
unacceptable and a new one needs to be picked.
Conceptually, it does not matter when random digits
are generated. Thus, conceptually, this is equivalent
to generating r=.?2 9 9 9 and repeating until 10#.r
is less than 1234.
> 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, that seems to
> satisfy your description of "uniform finite
> average number of discards".
I think that would make it non-uniform.
For example, with 10 dice 1234, this would
generate numbers where 1 is the first digit with
50% probability.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm