I need some help creating a rand number that will not come up with a number that has already been called. For example, a tic-tac-toe game which allows a player to play against a computer. This code will limit the numbers from 1-9, but they still repeat.
Code:#include <iostream> #include <cstdlib> #include <time.h> const int LOW = 1; const int HIGH = 9; using namespace std; int main() { int comp_choice; time_t seconds; time(&seconds); srand((unsigned int) seconds); comp_choice = rand() % (HIGH - LOW + 1) + LOW; cout<<"the computer picked: "<<comp_choice; return 0; }



3Likes
LinkBack URL
About LinkBacks



