Skip to content

Instantly share code, notes, and snippets.

@unprovable
Created November 17, 2017 17:09
Show Gist options
  • Save unprovable/c3710ebdbe118aa27dbd83030e48f123 to your computer and use it in GitHub Desktop.
Save unprovable/c3710ebdbe118aa27dbd83030e48f123 to your computer and use it in GitHub Desktop.
Random Periodicity Test Code for arduino (compiled in Arduino IDE)
long rand_i, rand_j, rand_k;
unsigned long i = 0, j = 0, k = 0;
void setup() {
// put your setup code here, to run once:
rand_i = random();
rand_j = random();
rand_k = random();
Serial.begin(9600);
while (!Serial) {}
Serial.print("starting num rand_i: "); Serial.println(rand_i, HEX);
Serial.print("starting num rand_j: "); Serial.println(rand_j, HEX);
Serial.print("starting num rand_k: "); Serial.println(rand_k, HEX);
pinMode(LED_BUILTIN, OUTPUT);
Serial.print("using rand_k");Serial.println(rand_k);
}
void loop() {
// put your main code here, to run repeatedly:
if ((i % 1000000) == 0) {
Serial.print("up to "); Serial.print(i); Serial.println(" iterations");
}
if (random() == rand_k) {
Serial.print("MATCH!! We got a match on "); Serial.print(rand_k); Serial.print(" in "); Serial.print(i, HEX); Serial.println(" operations.");
//i = 0;
while(true){
Serial.print("MATCH!! We got a match on "); Serial.print(rand_k); Serial.print(" in "); Serial.print(i, HEX); Serial.println(" operations.");
digitalWrite(LED_BUILTIN, HIGH);
delay(50000);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}; // stop the duino so we can see what the magic number is :-P Keep printing in case the serial port goes to sleep...
}
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment