Skip to content

Instantly share code, notes, and snippets.

@rahul8590
Last active December 19, 2015 10:59
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 rahul8590/5944423 to your computer and use it in GitHub Desktop.
Save rahul8590/5944423 to your computer and use it in GitHub Desktop.
In order to sample continuous stream of data (numbers). We need to pick up number whos probability of choosing is 1/ (n+1).
#sl is a sample list of numbers which is contiguously getting updated.
import random
def simple_sample(sl):
for x,y in enumerate(sl,1):
if random.random() < 1.0 / x:
sample_data = y
return sample_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment