Last active
August 29, 2015 14:20
-
-
Save juandesant/67ada2b238fcc0c82b2d to your computer and use it in GitHub Desktop.
Use NumPy to read random numbers as integers from /dev/random
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
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