Skip to content

Instantly share code, notes, and snippets.

View wandrson's full-sized avatar

Walter Anderson wandrson

  • Dallas, TX
View GitHub Profile
@wandrson
wandrson / display_ip.py
Last active May 20, 2017 21:03
Simple python script to display raspberry pi ip address using a Pimoroni Blinkt
#!/usr/bin/env python
import socket
from time import sleep
from blinkt import set_clear_on_exit, set_pixel, show
colors = [
[ 0, 0, 0],#0 black
[ 32, 32, 0],#1 brown
[255, 0, 0],#2 red
@wandrson
wandrson / DiceAnalysis.R
Created April 6, 2014 14:59
R script to analyze random data simulating a six sided die
# Analyze dice data to establish if it is random
setwd("~/Development/hardware-rng/avr-hardware-random-number-generation/Entropy/examples/Dice")
library(foreign)
library(prettyR)
sink("analysis.prn")
Dice.data <- read.csv("dice.txt")
Dice.data$Sum <- Dice.data$Die1 + Dice.data$Die2
png(filename="cumulative.png", width=800, height=600)
hist(Dice.data$Sum,
freq=FALSE,
@wandrson
wandrson / TrueRandomSeed.ino
Last active February 2, 2024 05:37
This is a simple straightforward and relatively lightweight example of how to seed the internal PRNG function with a truly random value
// TrueRandomSeed.ino
// This example sketch shows how to provide a truly random seed value to the built in
// library pseudo random number generator. This ensures that your sketch will be
// using a different sequence of random numbers every time it runs. Unlike the
// usually suggested randomSeed(analogRead(0)) this method will provide a much more
// uniform and varied seed value. For more information about the basic technique used
// here to produce a random number or if you need more than one such number you can
// find a library, Entropy from the following web site along with documentation of how
// the library has been tested to provide TRUE random numbers on a variety of AVR
// chips and arduino environments.
@wandrson
wandrson / due_hwrng_test.ino
Created April 5, 2014 18:28
A short Arduino Due sketch that streams 32-bit random numbers using the TRNG component on the ARM processor. Developed to test the validity of the entropy produced as part of updating my Arduino Entropy library to make use of this source, if used on a Due chip.
// DUE's TRNG 32 bits every 84 ticks
#include <sam.h>
#include <sam3xa/include/component/component_trng.h>
uint32_t test_hwrng()
{
static bool enabled = false;
if (!enabled) {
pmc_enable_periph_clk(ID_TRNG);
TRNG->TRNG_IDR = 0xFFFFFFFF;
@wandrson
wandrson / due_hwrng_speed_test.ino
Created April 5, 2014 18:24
A short Arduino Due sketch that measures the time it takes the Due's ARM processor's true random number generator to produce 1Mb of entropy.
// due_hwrng_speed_test.ino
// by Walter Anderson
// April 5, 2014
//
// This is a speed test run on an Arduino Due with an ATSAM3X8E-AU chip dated 1317, it produced the following
// output:
// Starting time test for speed of generation of hardware randrom number gebnrator.
// It took 262 milliseconds to generato 1,048,576 bytes of entropy!
// This equates to 4,002,198 bytes per second!
//
@wandrson
wandrson / long2bin.py
Last active August 29, 2015 13:57
This python program will convert up to a specified maximum number of 32-bit numbers to a binary file.
#! /usr/bin/python
import sys
import struct
try:
infilename = sys.argv[1]
outfilename = sys.argv[2]
maxsize = int(sys.argv[3])
except:
@wandrson
wandrson / RandomCardDraw.pde
Last active August 29, 2015 13:57
The following example demonstrates how to produce the numbers 1 to X in a random order, where each number only appears once, and that all numbers are produced.
// FILE: RandomCardDraw.ino
// AUTHOR: Rob Tillaart and Walter Anderson
// VERSION: 1.0.0
// PURPOSE: generate random sequence (optimized)
// DATE: April 24, 2014
// URL:
// The Entropy library provides true random numbers and can be obtained from:
// http://code.google.com/p/avr-hardware-random-number-generation/wiki/WikiAVRentropy
#include <Entropy.h>
@wandrson
wandrson / analyze.py
Created March 27, 2014 18:21
Python scrupt that performs basic tests (derived from ent utility) on a binary file and also produces both a histogram of the distribution of bytes as well as a scatter plot of those byte pairs. Useful for preliminary testing of quality of entropy (random) data sources.
#! /usr/bin/python
#
# This program will take a file name from the command line and analyze its entropy, using many of the same algorithms
# as the ent program from hotbits
import sys
import struct
import math
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab