Last active
December 19, 2015 10:59
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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