# Fill the array help

This is a discussion on Fill the array help within the C Programming forums, part of the General Programming Boards category; Could someone please explain to me what this for loop does in reference to the fill array with random numbers? ...

1. ## Fill the array help

Could someone please explain to me what this for loop does in reference to the fill array with random numbers? Thanks.

Code:
```void fillArray ( int grades [] )
{

int i;

for ( i= 0; i < 100;i++)
{
grades[i] = rand() % 100 + 1;
}
}```

2. Use the FAQ, Luke! Cprogramming.com FAQ > Generate random numbers? (Also known as RTFM.)

Quzah.

3. What does grades[i] = rand() % 100 + 1 mean in this code?

4. Do that thing where you actually click on the link I provided. Then do the part where you read what the link says. If you still don't understand, go read up on arrays, and while you are there, go back and read the part about math operators.

Quzah.

5. Originally Posted by IMMORTALX
What does grades[i] = rand() % 100 + 1 mean in this code?
It reduces the pseudorandom numbers generated into the range [1, 101), though it probably introduces a slight bias (that might not matter to you here) in the process.

6. Originally Posted by laserlight
It reduces the pseudorandom numbers generated into the range [1, 101), though it probably introduces a slight bias (that might not matter to you here) in the process.
Code:
```  /*
* Formula:
*    rand() % N   <- To get a number between 0 - N-1
*    Then add the result to min, giving you
*    a random number between min - max.
*/
rc = (rand() % (max - min + 1) + min);

return (rc);
}```

Quzah.

7. thanks

8. Originally Posted by IMMORTALX
thanks
Next time you want to know what something that butt simple does... use a printf() statement in your code to put it on the screen...
Code:
```void fillArray ( int grades [] )
{

int i;

for ( i= 0; i < 100;i++)
{
grades[i] = rand() % 100 + 1;