Author Topic: Random Seed using Micro controller floating pin  (Read 1726 times)

0 Members and 1 Guest are viewing this topic.

Offline UnordungTopic starter

  • Contributor
  • Posts: 49
  • Country: au
Random Seed using Micro controller floating pin
« on: January 31, 2019, 08:50:42 am »
Hello,
I recently created a simple project (electronic dice) which required a random function using the Arduino development platform. In this project I opted to use the random function with an analog Read as the seed.
Previously I had discovered that using this function I would consistently get higher numbers on the output of the function (once I created a box plot of the data).
To counter this I created a PCB based Antenna which in theory would amplify random noise and in turn provide a more random output.
Once I tested the results and created a histogram the results, did indeed seem to level out with no statistical outlier.

My question is, am I insane or did I get lucky?

The more I think about this the more confused I get. The floating pin is an antenna, it will naturally change its voltage in relation to the background noise. My thought process seems too simple, the bigger pin means bigger variation. Whilst it seemed to work and indeed created a more even histogram, I'm not entirely sure as to why.

To create a PCB antenna, is simply lengthening the trace enough to create a greater variation of noise on the pin?
Is there a more dare I say, "professional" / mature way to approach this using the Arduino platform?
Wouldn't the length of the PCB antenna translate to the frequency being amplified?
Given the frequency of Australian AC, would it make sense to "tune" the antenna to match the 50Hz frequency?

Kind regards,
Unordung



« Last Edit: January 31, 2019, 08:53:19 am by Unordung »
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 8076
  • Country: ca
Re: Random Seed using Micro controller floating pin
« Reply #1 on: January 31, 2019, 09:01:03 am »
I would bias an analog input to 50% vcc and run the adc, summing up the noise in the least 2 significant bits, no antenna.  After accumulating noise from a few k samples, use that number to feed your random number generator.
 
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10213
  • Country: nz
Re: Random Seed using Micro controller floating pin
« Reply #2 on: January 31, 2019, 09:19:08 am »
Another way is to combine all the random things you can find on your MCU,
Temp sensor
Floating ADC
ADC of supply rail
ADC of any extra bandgap references

Then store a large array of true random numbers in code/flash/eeprom and use above method to pick the number of positions to increment through the block by each time you need a random number.
This will mask any non-randomness in the floating adc/hardware system which can sometimes pick similar numbers.
But keep in mind the only values it will ever output are numbers in your array. So the array really needs to contain all numbers in the range require unless extra methods are done.
« Last Edit: January 31, 2019, 09:25:03 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4700
  • Country: au
  • Question Everything... Except This Statement
Re: Random Seed using Micro controller floating pin
« Reply #3 on: January 31, 2019, 09:23:51 am »
Shift your biases, the internal RC clock of an arduino is generally about 1-5% accurate, so you can use the beat frequency between it and the external crystal to make something very hard to externally influence.
https://sites.google.com/site/astudyofentropy/project-definition/timer-jitter-entropy-sources/entropy-library/arduino-random-seed
 

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3538
  • Country: es
Re: Random Seed using Micro controller floating pin
« Reply #4 on: January 31, 2019, 09:56:54 am »
One of my first projects decades ago was an electronic dice. You put your finger on a pad and you were the antenna collecting random noise. As long as your finger was on the contact the internal counter was counting, when you took off your finger the counter would stop.

A standard way of generating random numbers is by using white noise generated with a reverse  biased transistor emitter.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22365
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Random Seed using Micro controller floating pin
« Reply #5 on: January 31, 2019, 03:54:29 pm »
Add to the list of sources: different clock generators.  A classic is measuring the internal RC oscillator to an external crystal oscillator, or really anything else of reasonably known frequency will do.  Sampling one with the other using the capture input, take the LSBs off the count and use that.

Ambient electric fields are a poor source because they're basically mains 50/60Hz, potentially very predictable, also easily manipulated as mentioned.

In general, any source of modest entropy can be used (like these examples), and the resulting bit streams can be "pooled" into a common, higher rate bit stream.  This should then be sent into a scrambling function, like an LFSR or hash function, which generates a balanced 50% output and makes it difficult to predict the output, even if the inputs are known.  Then you sample the statistically clean output and generate dice rolls. :)

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3538
  • Country: es
Re: Random Seed using Micro controller floating pin
« Reply #6 on: January 31, 2019, 06:12:24 pm »
Add to the list of sources: different clock generators.  A classic is measuring the internal RC oscillator to an external crystal oscillator, or really anything else of reasonably known frequency will do.  Sampling one with the other using the capture input, take the LSBs off the count and use that.

Ambient electric fields are a poor source because they're basically mains 50/60Hz, potentially very predictable, also easily manipulated as mentioned.

In general, any source of modest entropy can be used (like these examples), and the resulting bit streams can be "pooled" into a common, higher rate bit stream.  This should then be sent into a scrambling function, like an LFSR or hash function, which generates a balanced 50% output and makes it difficult to predict the output, even if the inputs are known.  Then you sample the statistically clean output and generate dice rolls. :)

Tim
IMHO for a 1/6 die no high-quality random generator is needed. Take a divide by 6 counter and a fast-enough pulse stream and that is pretty much all you need.

At 60 Hz you would need to be able to release the button with a precision of 1/60 sec and that is assuming you could see the display which can easily be prevented. That is plenty enough IMHO. But, OK, want more? Use a 60 KHz oscillator. There ain't no one in the world who can time their push of a button with that precision. OK, make it 600 KHz.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5130
  • Country: bt
Re: Random Seed using Micro controller floating pin
« Reply #7 on: January 31, 2019, 06:33:21 pm »
Quote
My question is, am I insane or did I get lucky?
You did get lucky.
Generating random events/numbers is rocket science. There is only one true random generator known today, afaik - the radioactive decay.
Readers discretion is advised..
 

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3538
  • Country: es
Re: Random Seed using Micro controller floating pin
« Reply #8 on: January 31, 2019, 06:51:09 pm »
Quote
My question is, am I insane or did I get lucky?
You did get lucky.
Generating random events/numbers is rocket science. There is only one true random generator known today, afaik - the radioactive decay.
I disagree as explained in my previous post.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline Domagoj T

  • Frequent Contributor
  • **
  • Posts: 505
  • Country: hr
Re: Random Seed using Micro controller floating pin
« Reply #9 on: January 31, 2019, 07:49:19 pm »
I'll just leave this here:
 
The following users thanked this post: Wimberleytech


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf