Skip to content

Instantly share code, notes, and snippets.

@deanmalmgren
Created July 14, 2014 19:49
Show Gist options
  • Save deanmalmgren/ae6367fb719847c58232 to your computer and use it in GitHub Desktop.
Save deanmalmgren/ae6367fb719847c58232 to your computer and use it in GitHub Desktop.
random numbers in python distributions
"""Pipe the output of this script to another program to look at the CDF of the values. For example,
python random_numbers.py 1000 | sort -n | awk '{print $1, 1-(NR-1)/1000}' | xmgrace -
"""
import sys
import random
n = int(sys.argv[1])
for i in xrange(n):
print random.random() # random number between [0,1)
# print random.uniform(-1, 1) # random numbers between [-1, 1)
# print random.randint(1, 6) # rolling dice!
# print random.randrange(0, 100, 2) # even numbers between [0, 100]
# print random.gauss(0, 1) # standard normal
# print random.expovariate(10) # exponential distribution
# print random.betavariate(1, 1) # beta distribution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment