3

I am programming a microcontroller (PSoC5), which doesn't have a system time.

What is the best way to generate a seed to initialize srand?

TIA

Philip F.
  • 1,167
  • 1
  • 18
  • 33
  • `1` more than used last time? *Everytime you use `srand()` you could read/update a file with the seed.* – pmg Oct 02 '21 at 12:25

1 Answers1

6

If the chip has ADCs, one option is to take advantage of noise picked up on the ADCs. Basically, you can take a few reads of the ADCs, then bitwise AND to keep the least significant bit. Then use the all of the least significant bits sampled to generate your seed.

Jonathon S.
  • 1,928
  • 1
  • 12
  • 18