do while loop and modulus question - lotto picker
reference: C ALL IN ONE DESK REFERENCE pg 40.
The code below creates random numbers and displays them. It keeps a track of the numbers generated so they are not repeated. Similar to the lotto
The trouble I'm having is with the do while loop specifically while(numbers[ball]). Does it mean to say while numbers[ball]=1 it should repeat ?
Also, lets say a random number 20 is created. What does ball=rand()%RANGE be equal to? 0.4?
Code:
#include <stdio.h>
#include "stdafx.h"
#include <stdlib.h>
#include <time.h>
#define RANGE 50
#define BALLS 6
int main()
{
int numbers[RANGE];
int c,ball;
puts("LOTTO PICKER\n");
srand((unsigned)time(NULL));
//initialize the array
for(c=0;c<RANGE;c++)
numbers[c]=0; //all 50 elements are initialized to 0
printf("Press Enter to pick this week's numbers:");
getchar();
//drawing numbers
puts("Here they come");
for (c=0;c<BALLS;c++)
{
do
{
ball=rand()%RANGE;
}while (numbers[ball]);
numbers[ball]=1;
printf("%2d ",ball+1);
}
getchar();
getchar();
}