c++ - Random list of numbers -
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <math.h> int main() { int i; int diceroll; for(i=0; < 20; i++) { printf("%d \n", rand()); } return 0; }
this code wrote in c (codeblocks) random numbers, problem same sequence: 41,18467,6334,26500
etc...
i'm still learning please try explain you're talking 8 year old d:
you same sequence each time because seed random number generator isn't set. need call srand(time(null))
this:
int main() { srand(time(null)); ....
Comments
Post a Comment