I got this code from the FAQ section... I've edited the values because I only need values from 1-6.
I don't understand how most of it works, especially the rand() and srand() functions, and the GetRand function. help?Code:#include <stdio.h> #include <stdlib.h> int GetRand(int min, int max); int main(void) { int i, r; for (i = 0; i < 1; i++) { r = GetRand(1, 6); printf ("Your number is %d\n", r); } return(0); } int GetRand(int min, int max) { static int Init = 0; int rc; if (Init == 0) { srand(time(NULL)); Init = 1; } rc = (rand() % (max - min + 1) + min); return (rc); }



LinkBack URL
About LinkBacks


