|
From: Ioannis V. <iv...@em...> - 2003-03-20 14:11:59
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of swagat kumar > Sent: Thursday, March 20, 2003 10:10 AM > To: dev...@li... > Subject: [Dev-C++] how to use "srand" > > > Hi! > friends...i have got a doubt... > > how to use srand() function. how to define the seed for this. > suppose i want to generate a random number between 0 and 10. > then what seed should i use... > > though rand() function works fine....i just wanted to know > the difference beween srand() and rand()... Rand() defines a pseudo-random sequence. Srand() defines the starting point based on a seed. So if you do not srand(), or srand() the same number you will always getting the same sequence. So, better do that: /* C */ #include <stdlib.h> #include <time.h> /* ... */ int x; /* initialize only once */ srand(time(NULL)); x=rand(); /* ... */ x=rand(); /* etc */ Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |