I have been working on an assignment, where I have to create a given number of arrays and fill them up with random data. The approach I would like to follow is I want the arrays to be filled with data, only a percentage. The problem is that for every array, the random values are in the same position and not spread how I would like.
I have been creating the arrays in this way:
int **array = malloc(DOC * sizeof *array);
for (i = 0; i < DOC; i++)
{
array[i] = malloc(MAXWORDS * sizeof **array);
}
and filling them using :
srand((unsigned) time(&t));
and
for(i = 0; i < DOC; i++){
for(j = 0; j < MAXWORDS; j++){
array[i][rand() %percentage]=rand() %VALUE;
}
}
Where
int percentage = rand() %MAXWORDS/10;
MAXWORDS defines the lenght of the array DOC the number of arrays VALUE is the max random value
As you can see the random values are all behaving identically. I know that this has to do with the way that srand depends on the time to generate the numbers, and the execution of the program is really fast, so the similar data are because of the "similar" time. So what I am asking is for either a different day to generate random values or some trick I could do to fill the arrays differently.
spread how i would like? You want gaps in the array? A broader range of random integers?