histogram of os.urandom 16bits

  |   Source
In [6]:
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
from collections import defaultdict
import os, sys
In [17]:
rnds = os.urandom(1000000)
nums = [int.from_bytes(rnds[i:i+2], sys.byteorder) for i in range(0,len(rnds), 2)]
In [18]:
hist = defaultdict(int)
In [19]:
for p in nums:
    hist[p] += 1
In [20]:
xs = sorted(hist.keys())
ys = [hist[i] for i in xs]
In [21]:
plt.bar(xs,ys)
Out[21]:
<Container object of 65501 artists>
Comments powered by Disqus