Skip to content

Instantly share code, notes, and snippets.

@CamDavidsonPilon
Created September 11, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CamDavidsonPilon/1e55dd74bfc1d65aeb6213cfc6ffc4e7 to your computer and use it in GitHub Desktop.
Save CamDavidsonPilon/1e55dd74bfc1d65aeb6213cfc6ffc4e7 to your computer and use it in GitHub Desktop.
def sample(N=2):
while True:
S_N_minus_1 = sum([random() for _ in xrange(N-1)])
if S_N_minus_1 >= 1:
continue
uN = random()
if S_N_minus_1 + uN >= 1:
return uN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment