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.
Random numbers same each time. Seed?
Moderator: Benj
-
- Valued Contributor
- Posts: 1191
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: Random numbers same each time. Seed?
You could use
in a C block.
Use a timer or a counter to get a 'random' seed.
Martin
Code: Select all
srand(seed);
Use a timer or a counter to get a 'random' seed.
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Random numbers same each time. Seed?
Please post your flowchart If you still require help after Martins helpful suggestion.
Martin