Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino Pseudo-Random White Noise Source
// Quick test for random bit generation timing
// Ed Nisley KE4ZNU - 2017-10-25
// Observe output bit on an oscilloscope
// LFSR info https://en.wikipedia.org/wiki/Linear-feedback_shift_register
// This code uses the Galois implementation
// Coefficients from https://users.ece.cmu.edu/~koopman/lfsr/index.html
#define PIN_RND 13
#include <Entropy.h>
uint32_t Rnd;
byte LowBit;
void setup() {
Serial.begin(57600);
Serial.println("Random bit timing");
Serial.println("Ed Nisley KE4ZNU - 2017-10-25");
Entropy.initialize();
pinMode(PIN_RND,OUTPUT);
uint32_t Seed = Entropy.random();
Serial.print("Seed: ");
Serial.println(Seed,HEX);
randomSeed(Seed);
do {
Rnd = random();
} while (!Rnd); // get nonzero initial value
}
void loop() {
// digitalWrite(PIN_RND,Rnd & 1); // about 55 us/bit
// Rnd = random();
LowBit = Rnd & 1;
digitalWrite(PIN_RND,LowBit); // about 6 us/bit
Rnd >>= 1;
Rnd ^= LowBit ? 0x80000057ul : 0ul;
}
@ednisley

This comment has been minimized.

Copy link
Owner Author

ednisley commented Oct 26, 2017

More details on my blog at http://wp.me/poZKh-78y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.