geometric-random* ( p rnd -- n )


Vocabulary
random

Inputs
pan object
rndan object


Outputs
nan object


Definition


:: geometric-random* ( p rnd -- n )
p 0.3333333333333333 >= [
1.0 p - :> q rnd random-unit* :> U 1 p p
[ U over > ] [ [ 1 + ] [ q * ] [ dupd + ] tri* ] while
2drop
] [
1.0 rnd random-unit* - log 1.0 p - log /
ceiling >integer
] if ;