Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
from bashplotlib.histogram import plot_hist
import random
import sys
if __name__ == '__main__':
print
if sys.argv[1] == 'a':
samples_a = [ random.choice([0,1]) for x in range(1*10**6) ]
print('[sample_a] 1 => %i' % samples_a.count(1))
print('[sample_a] 0 => %i' % samples_a.count(0))
print('\n[sample_a] ratio 1/0 => %f' % (
float(samples_a.count(1)) / samples_a.count(0)))
print('-'*40)
plot_hist(samples_a)
else:
samples_b = [ random.random() for x in range(1*10**6) ]
samples_b = map(lambda x:int(round(x)), samples_b)
print('[sample_b] 1 => %i' % samples_b.count(1))
print('[sample_b] 0 => %i' % samples_b.count(0))
print('\n [sample_b] ratio 1/0 => %f' % (
float(samples_b.count(1)) / samples_b.count(0)))
print('-'*40)
plot_hist(samples_b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment