Best way to seed random that doesn't pig space

I need a lightweight reliable way to seed random. Ideas?

One often suggested idea is to attach a wire to an analog pin, leave it floating and use analogRead to get your seed.

But pigs will always take space!

Lefty

One thing I thought of was to take 32 analogue readings and shift the LSBs into a long.

http://arduino.cc/forum/index.php/topic,66206.0.html

One often suggested idea is to attach a wire to an analog pin, leave it floating and use analogRead to get your seed.

The original poster wanted reliable. Floating-pins are not.

But pigs will always take space!

The ones in Texas sure do...

I need a lightweight reliable way to seed random. Ideas?

That is a lot of unqualified information. What do you consider to be "reliable" and "lightweight"?

More threads -- this is a recurring topic:

http://arduino.cc/forum/index.php/topic,69860
http://arduino.cc/forum/index.php/topic,69877

Can you clarify what you mean by "pig space"? Code-wise, even a complex solution is going to fit in a few hundred bytes at most. Electronics solutions would use maybe 6 components, so not huge real-estate wise. What's the constraint you have in mind WRT "pigging"?

I experimented a bit with this code on an Uno with nothing at all connected to A0. There is noise there, but it looks to me an awful lot like a ~60 Hz sine wave from what I can see. There tend to be a lot of repeated values read in -- maybe 10 in a row with the same value -- and after 0x1e0 is guaranteed to be 0x1e0, 0x1e1 or 0x1df -- not all that random at all. All of the entropy is in the timing, so you have to take lots of observations. And the source of the noise looks like an electric field outside the Arduino, which may be different or not present at all depending on a lot of things.

uint32_t get_seed(int pin)
{

uint16_t aread;
union {
   uint32_t as_uint32_t;
   uint8_t  as_uint8_t[4];
} seed;
uint8_t i, t;


    /* "aread" shifts 3 bits each time and the shuffle
     * moves bytes around in chunks of 8.  To ensure
     * every bit is combined with every other bit,
     * loop at least 3 x 8 = 24 times.  A few hundred
     * seems safe.
     */
    for (i = 0; i < 240; i++) {

       /* Shift three bits of A2D "noise" into aread.
        */
       aread <<= 3;
       aread |= analogRead(pin) & 0x7;

       /* Now shuffle the bytes of the seed
        * and xor our new set of bits onto the
        * the seed.
        */
       t = seed.as_uint8_t[0];
       seed.as_uint8_t[0] = seed.as_uint8_t[3];
       seed.as_uint8_t[3] = seed.as_uint8_t[1];
       seed.as_uint8_t[1] = seed.as_uint8_t[2];
       seed.as_uint8_t[2] = t;

       seed.as_uint32_t ^= aread;
   }

   return(seed.as_uint32_t);
}

More importantly, what are your operational parameters - IOW, what degree of randomness is acceptable? Are you using the RNG for some secure operation (eg, transmitting financial data), or are you just wanting less deterministic randoms?

I've blathered on ad nauseum regarding seeding RNGs in the other threads on this board so will avoid doing so here. :stuck_out_tongue:

I'll just leave this here: HotBits: Genuine Random Numbers

retrolefty:
But pigs will always take space!

Pigs? Space?