When I am trying to generate a random number 0 through int:
//Populate Currently Allocated Reasource for each customer
for (i = 0; i < NUMBER_OF_CUSTOMERS; i++)
{
printf("%d:[ ",i);
for (j = 0; j < NUMBER_OF_RESOURCES; j++)
{
allocation[i][j] = rand() % maximum[i][j];
printf("%d ",allocation[i][j]);
}
printf("] \n\n");
}
I get a floating point exception when rand() is 0, then % maximum[i][j] where maximum[][] is an int double array.
Are there any better means of creating a random number without the floating point error caused by 0 modulo int?
Aucun commentaire:
Enregistrer un commentaire