Skip to main content
added 520 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 25 bytes

c(sample(99,rexp(1),T),0)

Try it online!

p(0) at each iteration is (e-1)/e.
p(each other number) at each iteration is (1/e)*(1/99).

Obviously this choice of random distribution gives a rather unsatisfying-looking output (since most of the runs are rather short). So this link uses the same approach, but changes p(0) to roughly 0.01 to illustrate some longer runs...

What's going on?

            rexp(1)         # First determine where the '0' will occur:
                            # We generate a single random number using
                            # an exponential distribution with a
                            # rate parameter equal to 1
                            # (so the chance of any value x is e^-x).  
c(                    ,0)   # Now place '0' at the subsequent position, 
  sample(99,rexp(1),T)      # and fill all the previous positions with
                            # numbers sampled from 1 to 99,
                            # with replacement (specified by the 'T' for TRUE).  

R, 25 bytes

c(sample(99,rexp(1),T),0)

Try it online!

p(0) at each iteration is (e-1)/e.
p(each other number) at each iteration is (1/e)*(1/99).

Obviously this choice of random distribution gives a rather unsatisfying-looking output (since most of the runs are rather short). So this link uses the same approach, but changes p(0) to roughly 0.01 to illustrate some longer runs...

R, 25 bytes

c(sample(99,rexp(1),T),0)

Try it online!

p(0) at each iteration is (e-1)/e.
p(each other number) at each iteration is (1/e)*(1/99).

Obviously this choice of random distribution gives a rather unsatisfying-looking output (since most of the runs are rather short). So this link uses the same approach, but changes p(0) to roughly 0.01 to illustrate some longer runs...

What's going on?

            rexp(1)         # First determine where the '0' will occur:
                            # We generate a single random number using
                            # an exponential distribution with a
                            # rate parameter equal to 1
                            # (so the chance of any value x is e^-x).  
c(                    ,0)   # Now place '0' at the subsequent position, 
  sample(99,rexp(1),T)      # and fill all the previous positions with
                            # numbers sampled from 1 to 99,
                            # with replacement (specified by the 'T' for TRUE).  
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 25 bytes

c(sample(99,rexp(1),T),0)

Try it online!

p(0) at each iteration is (e-1)/e.
p(each other number) at each iteration is (1/e)*(1/99).

Obviously this choice of random distribution gives a rather unsatisfying-looking output (since most of the runs are rather short). So this link uses the same approach, but changes p(0) to roughly 0.01 to illustrate some longer runs...