Random numbers same each time. Seed?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
stylo
Posts: 23
Joined: Mon Mar 02, 2009 9:30 am
Been thanked: 3 times
Contact:

Random numbers same each time. Seed?

Post 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.

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Random numbers same each time. Seed?

Post 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

medelec35
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?

Post by medelec35 »

Please post your flowchart If you still require help after Martins helpful suggestion.
Martin

Post Reply