I have the below function to generate a random number within a min, max
range:
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
//..
int GenerateRandom(int min, int max) //range : [min, max)
{
static bool first = true;
if (first)
{
srand(time(NULL)); //seeding for the first time only!
first = false;
}
return min + rand() % (max - min); // returns a random int between the specified range
}
I want to include c++ create a random decimal between 0.1 and 10 functionality or/and create a random decimal number between two other numbers functionality into the above function without excluding negatives. So I want to get the decimal between "any" range: [negative, negative]
, [negative, positive]
and [positive, positive]
Aucun commentaire:
Enregistrer un commentaire