#!/usr/bin/env python # coding: utf-8 # # Counter-Based Random Number Generation # In[38]: from Crypto.Cipher import AES import os import numpy as np import matplotlib.pyplot as plt # In[7]: #secret = os.urandom(BLOCK_SIZE) secret = np.array([23842839,234234,2342314,2342342], dtype=np.uint32) # In[12]: counter = np.array([1,0,0,0], dtype=np.uint32) # In[13]: aes = AES.new(secret) # In[14]: aes.encrypt(counter) # In[15]: aes.encrypt(counter) # In[33]: x = np.fromstring(aes.encrypt(counter), dtype=np.uint32) counter[0] += 1 x # ## Batched Random Number Generation # In[43]: counters = np.zeros((100000, 4), dtype=np.uint32) counters[:, 0] = np.arange(len(counters)) # In[44]: numbers = np.fromstring(aes.encrypt(counters), dtype=np.uint32).reshape(-1) # In[45]: plt.hist(numbers) # * How would you convert that to real numbers between 0 and 1?