Help with a do...while array
I started working my way through "C All-In-One Desk Reference For Dummies" by Dan Gookin. I've made it to page 240 and got stuck on a do...while statement. The program generates 6 lotto numbers and disregards any duplicates. The snip-it of code I'm stuck on is:
Code:
do
{
ball = random() % RANGE;
}
while(numbers[ball];
This segment of the code is apparently checking to make sure the random number generated hasn't already been added to the array but I cannot figure out what calculation/check while(numbers[ball]) is performing to spin the loop. There is no operator present. Any help would be appreciated.
Here is the full code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANGE 50
#define BALLS 6
int main()
{
int numbers[RANGE]; // 0 to 49
int c,ball;
puts("L O T T O P I C K E R\n");
srandom((unsigned)time(NULL));
/* initialize the array */
for(c=0;c<RANGE;c++) // if c < 50
numbers[c]=0;
printf("Press Enter to pick this week's numbers:");
getchar();
/* draw the numbers */
puts("Here they come:");
for(c=0;c<BALLS;c++)
{
/* see if a number has already been drawn */
do
{
ball = random() % RANGE;
}
while(numbers[ball]);
/* Number drawn */
numbers[ball] = 1;
printf(" %i ",ball+1);
}
printf("\n\nGood luck in the drawing!\n");
return(0);
}