So I'm trying to look for a very efficient way to generate number from a range. Basically, I am writing a code for a Tic Tac Toe between computer vs computer. I want to make sure the computer mark X/O randomly in a 2D array. A random point will be array[random][random].
For example, I want to make a move on a TicTacToe size 3x3
I use:
int range = 3;
int random = rand() % range + 1;
The random number I got is only 3 after hundreds of time, which leads to invalid moves on the game.
I'm wondering if you can give me an idea how to generate a very linearly random integer between a small range. Thanks a lot!