Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active August 29, 2015 14:20
Show Gist options
  • Save juandesant/67ada2b238fcc0c82b2d to your computer and use it in GitHub Desktop.
Save juandesant/67ada2b238fcc0c82b2d to your computer and use it in GitHub Desktop.
Use NumPy to read random numbers as integers from /dev/random
import numpy as np
randomFile = open("/dev/random", "rb") # open for reading, binary
#define an integer type for reading
intType = np.dtype([('random', int)])
randomList = np.fromfile(randomFile,dtype=intType, count=10)
# Random generator
def random_int_generator(randomFile=randomFile):
yield np.fromfile(randomFile,dtype=intType, count=1)[0][0]
randomList2 = [random_int_generator().next() for x in range(0,10)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment