|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
SRand() |
Posted: Sun Feb 02, 2003 3:25 pm |
|
|
Hi there,
I wrote a code that uses rand() function and i want to start randomize engine with srand() function.I use this code in c++ compiler without problem in my pc, but ccs does not compile.Would you offer another way for it? What is wrong with it?
Thank you.
srand( (unsigned)time( NULL ) );
___________________________
This message was ported from CCS's old forum
Original Post ID: 11211 |
|
|
R.J.Hamlett Guest
|
Re: SRand() |
Posted: Sun Feb 02, 2003 4:09 pm |
|
|
:=Hi there,
:=I wrote a code that uses rand() function and i want to start randomize engine with srand() function.I use this code in c++ compiler without problem in my pc, but ccs does not compile.Would you offer another way for it? What is wrong with it?
:=Thank you.
:=
:=srand( (unsigned)time( NULL ) );
Very simple. Your PIC has no awareness of 'time', and no time function...
You can get a good effect, by simply reading something like the timer0 counter, and using this to initialise the random number generator.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 11212 |
|
|
sh1
Joined: 04 Mar 2005 Posts: 5
|
|
Posted: Mon Jun 13, 2005 6:31 am |
|
|
use:
srand(get_rtcc());
it generates the seed based on current time counter. |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 13, 2005 6:40 am |
|
|
Has the thread 'come back to life', from 2003!.
Seeding with the rtcc, is not a good idea. The problem is that if this is done at the start of a normal program, the rtcc, will have started counting when the chip woke up, and will always contain the same value. Seeding with the rtcc, is great, if you do it inside some event that is asynchronous to the main code (the receipt of the first character on an RS232 port for example).
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|