im looking for a faster method, which allows me, to get a random number from a certain pool of numbers which are stored in an array.
I'll need the method multiple times, and the current method is terribly slowing down the code.
#include <cstdlib>
#include <ctime>
int main()
{
const int size = 8;
int numberArray[size] = { 0, 0, 3, 4, 0, 6, 7, 0 };
srand(time(0));
int rndIndex;
int rndNumber;
do
{
rndIndex = rand() % size;
rndNumber = numberArray[rndIndex];
} while (rndNumber <= 0);
}
I like to get a random number from the array, except the random number is less than 0
Aucun commentaire:
Enregistrer un commentaire