im writing a simple lotto simulator, not finished, but i when drawing the numbers they are all the same unless a lot of time goes by
Im using srand() like this
But my code is executing so fast that im getting the same number, unless i do like 3000+ draws, then it will change the numbers a couple timesCode:srand(time(NULL)); randnum = 1 + rand() % 25;
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int numBalls, numDraw; int randnum; printf("Enter number of Lottery Numbers to simulate: "); scanf("%d", &numBalls); printf("Enter the number of lottery draws to simulate: "); scanf("%d", &numDraw); int a, b; for (a = 0; a < numDraw; a++) { for (b = 0; b < numBalls; b++) { srand(time(NULL)); randnum = 1 + rand() % 25; printf("%d\t", randnum); if (b == numBalls) { printf("\n"); } } } }



LinkBack URL
About LinkBacks




