Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize random without time

Tags:

c

random

srand

psoc

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

like image 999
Philip F. Avatar asked May 02 '26 21:05

Philip F.


1 Answers

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.

like image 182
Jonathon S. Avatar answered May 05 '26 10:05

Jonathon S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!