Page 1 of 1

Random numbers same each time. Seed?

Posted: Sun Aug 12, 2018 12:17 pm
by stylo
Hi,

I'm trying to generate a random number on a button press. 1 - 10.

In FC7, I'm just using a C snippet containing "Ran1 = random () % 10 + 1"

This works fine in software, but the moment I burn it to the chip (using a "12F1840"). I get the same sequence of random numbers every time.

I'm asuming this is because the seed being used is the same each time, but for the life of me I cant find out how to change the seed.

Any help would be much appreciated.

Thanks.

Re: Random numbers same each time. Seed?

Posted: Sun Aug 12, 2018 2:40 pm
by mnf
You could use

Code: Select all

srand(seed);
in a C block.

Use a timer or a counter to get a 'random' seed.

Martin

Re: Random numbers same each time. Seed?

Posted: Sun Aug 12, 2018 3:36 pm
by medelec35
Please post your flowchart If you still require help after Martins helpful suggestion.