Hi, this one has me stumped.
Is there a way to create a psudo random number, between limits in flowcode or via a C call?
I wish to create a delay with a random length between 0.5 and 4 seconds.
J.
Im using a PIC 18F 2585
PIC Random Nunber
-
- Posts: 197
- http://meble-kuchenne.info.pl
- Joined: Sun Dec 20, 2020 6:06 pm
- Has thanked: 75 times
- Been thanked: 54 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: PIC Random Nunber
Hi
Generally speaking, yes, you can.
If you do a search in the forum you will find pleanty of info such as this
https://www.matrixtsl.com/mmforums/view ... 97#p106397
You might also want to include a truly random variable such as a temperature reading or an ADC on a floating pin to help mix it up
Regards
EDIT...
I see Martinn beat me to it
Generally speaking, yes, you can.
If you do a search in the forum you will find pleanty of info such as this
https://www.matrixtsl.com/mmforums/view ... 97#p106397
You might also want to include a truly random variable such as a temperature reading or an ADC on a floating pin to help mix it up

Regards
EDIT...
I see Martinn beat me to it

Re: PIC Random Nunber
Ah Thanks Guys.
argh flipping heck..yeah found it now! Thanks Martin.
I did several searches on the current FC forum and did not find anything, FC is great on some of its features these days but sometimes even the simplest things are darn hard to find.
argh flipping heck..yeah found it now! Thanks Martin.

I did several searches on the current FC forum and did not find anything, FC is great on some of its features these days but sometimes even the simplest things are darn hard to find.
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: PIC Random Nunber
Hi
The "old" forum is a great source of knowledge going back to stoneage times
Regards
The "old" forum is a great source of knowledge going back to stoneage times

Regards
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: PIC Random Nunber
The issue with Random() is that the resultant sequence will be the same on every run. Great idea from Iain to use a 'genuinely random number (possibly as a seed) - for example current time in ms or a floating pin..
You can do this with a C Block and
srand(FCL_SEED);
Where .seed is the value you want to use as a seed (so something from an ADC etc)
Using the same seed is good for testing purposes - you get the same sequence every time - but may not be so good for games or other programs that rely on the user not knowing what is going to happen..
You can do this with a C Block and
srand(FCL_SEED);
Where .seed is the value you want to use as a seed (so something from an ADC etc)
Using the same seed is good for testing purposes - you get the same sequence every time - but may not be so good for games or other programs that rely on the user not knowing what is going to happen..