CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SRand()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
No_Fear
Guest







SRand()
PostPosted: Sun Feb 02, 2003 3:25 pm     Reply with quote

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()
PostPosted: Sun Feb 02, 2003 4:09 pm     Reply with quote

:=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

View user's profile Send private message

PostPosted: Mon Jun 13, 2005 6:31 am     Reply with quote

use:

srand(get_rtcc());

it generates the seed based on current time counter.
Ttelmah
Guest







PostPosted: Mon Jun 13, 2005 6:40 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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