# unique randomly generated numbers

• 11-07-2001
grobe59
unique randomly generated numbers
i am currently working on a program that generates 50 sets of six randomly generated lottery numbers, using a two dimensional array. i have been able to generate and sort these numbers in ascending order. however, my method for testing each row of the array for unique numbers is not working 100%. i have included the code as follows from a much earlier assignment. if someone could give me a clue as to how to test just 6 ramdomly generated numbers for uniqueness, i'me sure i can take it from there. even a simple algorithm might be all i need.

//T5Be01
//this program generates six random numbers
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <fstream.h>

void main()
{
short num1 = 0;
short num2 = 0;
short num3 = 0;
short num4 = 0;
short num5 = 0;
short num6 = 0;

srand (time(NULL));
num1 = 1 + rand() % (54 - 1 + 1);
num2 = 1 + rand() % (54 - 1 + 1);
num3 = 1 + rand() % (54 - 1 + 1);
num4 = 1 + rand() % (54 - 1 + 1);
num5 = 1 + rand() % (54 - 1 + 1);
num6 = 1 + rand() % (54 - 1 + 1);

cout<< "Num 1 = "<< num1<< endl;
cout<< "Num 2 = "<< num2<< endl;
cout<< "Num 3 = "<< num3<< endl;
cout<< "Num 4 = "<< num4<< endl;
cout<< "Num 5 = "<< num5<< endl;
cout<< "Num 6 = "<< num6<< endl;
}:confused:
• 11-07-2001
Stoned_Coder
you will find this easier to do if you ditch the array and use a binary search tree.Cprogramming.com has a tutorial... go have a read and come back if you dont understand.