#include <stdlib.h>
|
void
srand (unsigned seed); |
int
rand (void); |
The srand function never returns.
#include <stdlib.h> ).
The srand function sets its argument seed as the seed for a new sequence of pseudo-random numbers to be returned by rand. These sequences are repeatable by calling srand with the same seed value. If no seed value is provided, the functions are automatically seeded with a value of 1. The |
#include <stdlib.h> #include <stdio.h> int main( void ) { int randArray[20]; int i=0; while(i<20) { randArray[i]=rand(); printf("\n%d", randArray[i]); i++; } return 0; }
Output
16807 282475249 1622650073 984943658 1144108930 470211272 101027544 1457850878 1458777923 2007237709 823564440 1115438165 1784484492 74243042 114807987 1137522503 1441282327 16531729 823378840 143542612
#include <stdlib.h> #include <stdio.h> int main( void ) { int seedVal = 45454652; int randVal; srand(seedVal); randVal=rand(); printf("Random Value returned is %d"), randVal); }
Output
Random Value returned is 1599641479
© 2005-2007 Nokia |