11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Library FunctionsSRANDSynopsis#include void srand (unsigned int seed)DescriptionThe srand() function initializes the random number generator accessed by rand() with the givenseed. This provides a mechanism for varying the starting point of the pseudo-random sequenceyielded by rand(). On the z80, a good place to get a truly random seed is from the refresh register.Otherwise timing a response from the console will do, or just using the system time.Example#include #include #include voidmain (void){time_t toc;int i;}time(&toc);srand((int)toc);for(i = 0 ; i != 10 ; i++)printf("%d\t", rand());putchar(’\n’);See Alsorand()196

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!