**I have a task:**

*Lottery number generator. In the Finnish Lotto you need to pick 7 numbers*

out of 39. Write a function, which picks a random number from 1 to 39.

After that write a program, which generates a random set of Lotto numbers

(a Lotto ticket). Notice that the same number cannot appear in the set

twice.

Hint: declare an integer array containing 40 elements and initilize all

its values to zero. After picking a random number, test if the element

value in that index is zero. If it is, accept the number and set the value

in that index to 1. Otherwise discard the number and pick a new one.

After you have successfully picked 7 numbers, you Lotto ticket is ready.

Finally iterate through the array and print the indexes in which the

element value is 1.

out of 39. Write a function, which picks a random number from 1 to 39.

After that write a program, which generates a random set of Lotto numbers

(a Lotto ticket). Notice that the same number cannot appear in the set

twice.

Hint: declare an integer array containing 40 elements and initilize all

its values to zero. After picking a random number, test if the element

value in that index is zero. If it is, accept the number and set the value

in that index to 1. Otherwise discard the number and pick a new one.

After you have successfully picked 7 numbers, you Lotto ticket is ready.

Finally iterate through the array and print the indexes in which the

element value is 1.

**And here is my code:**

**#include <stdio.h>**

#include <stdlib.h>

#include <time.h>

int myRand();

int main()

{

srand(time(NULL));

int checkArr[40] = {};

int counter;

int counter2;

int counter3;

int sumOfones = 0;

for (counter = 0;counter < 7; counter++){

if (checkArr[myRand()] == 0){

checkArr[myRand()] = 1;

}

else if (checkArr[myRand()] == 1)

checkArr[myRand()] = 1;

}

#include <stdlib.h>

#include <time.h>

int myRand();

int main()

{

srand(time(NULL));

int checkArr[40] = {};

int counter;

int counter2;

int counter3;

int sumOfones = 0;

for (counter = 0;counter < 7; counter++){

if (checkArr[myRand()] == 0){

checkArr[myRand()] = 1;

}

else if (checkArr[myRand()] == 1)

checkArr[myRand()] = 1;

}

**for (counter2 = 0; counter2 < 39; counter2++){**

if (checkArr[counter2] == 1)

// sumOfones = sumOfones + checkArr[counter2];

printf("%d ", counter2+1);

}

printf("\n\n");

for(counter3 = 0; counter3 < 39; counter3++){

printf("%d", checkArr[counter3]); // For testing purpose

}

system("PAUSE");

return 0;

}

int myRand(){

int numR = (rand() % 38) + 1;

}

if (checkArr[counter2] == 1)

// sumOfones = sumOfones + checkArr[counter2];

printf("%d ", counter2+1);

}

printf("\n\n");

for(counter3 = 0; counter3 < 39; counter3++){

printf("%d", checkArr[counter3]); // For testing purpose

}

system("PAUSE");

return 0;

}

int myRand(){

int numR = (rand() % 38) + 1;

}

**/* My problem is that sometimes program shows 5 or 6 numbers insted of 7.**

**It's because of random number sometimes gives same number twice.**

Do you know how to make FOR loop give 7 different numbers? (Otherwise discard the number

Do you know how to make FOR loop give 7 different numbers? (Otherwise discard the number

**and pick a new one.(q))**

I hope for your help friends. I'm stucked */

I hope for your help friends. I'm stucked */