srand(time(NULL)); sets the initial seed of rand() to the current time via the time(NULL) function (passing in a null pointer). you should generate non-repeating "random" numbers if there was an unlimited range. but you want 1-100, thus you will get some repeats using this method. thus i would initialize a system of checks. store the numbers in an array, vector, etc. and then compare incoming "random" numbers to those stored in the data structure.Code:#include <cstdlib> ... int limiter = 100; int limited; srand(time(NULL)); limited = (int) (limiter * rand() / (RAND_MAX + 1.0)); // RAND_MAX = the max value that rand() can return, (int) casts it to an int, thus dropping whatever decimal there is std::cout << limited << endl; ...




Reply With Quote