Skip to content

Instantly share code, notes, and snippets.

@rlee287
Created September 28, 2018 15:04
Show Gist options
  • Save rlee287/02f32ca0cab9b6845eac38fcc1064885 to your computer and use it in GitHub Desktop.
Save rlee287/02f32ca0cab9b6845eac38fcc1064885 to your computer and use it in GitHub Desktop.
A python script to matplotlib plot the estimated entropy of a system
import matplotlib.dates
import pylab as plt
import numpy as np
from datetime import datetime
def get_entropy():
with open("/proc/sys/kernel/random/entropy_avail","r") as fil:
res=fil.read()
return int(res)
initdate=datetime.utcnow()
datelist=[initdate]
entropyvals=[get_entropy()]
plt.ion()
graph = plt.plot_date(matplotlib.dates.date2num(datelist),entropyvals,'-')[0]
while True:
datelist.append(datetime.utcnow())
entropyvals.append(get_entropy())
nowdate=datetime.utcnow()
graph.set_xdata(matplotlib.dates.date2num(datelist))
graph.set_ydata(entropyvals)
plt.xlim(initdate,nowdate)
plt.ylim(min(entropyvals)-1,max(entropyvals)+1)
plt.draw()
plt.pause(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment