Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tehy

macrumors regular
Original poster
Jan 15, 2006
109
0
Finland
Hi,

I got 5 random number:

srandom(time(NULL));

luku = random() % 70 + 1;
luku2 = random() % 70 + 1;
luku3 = random() % 70 + 1;
luku4 = random() % 70 + 1;
luku5 = random() % 70 + 1;

What would be the best and easiest way to check that all numbers are different numbers?
 

Vlade

macrumors 6502a
Feb 2, 2003
966
4
Meadville, PA
Firsts its going to be easier if you make them into an array, then its easy to add more numbers later and makes the code smaller and easier to manage

int luku[5];
int i; //loop counter
srandom(time(NULL));

for(i=0; i<5; i++) {
luku = random() % 70 + 1;
}

Then to check them add this code

int j; //Second loop counter
for(i=0; i<5; i++) {
for(j=i+1;j<5;j++) {
if (loku == loku[j]) //Then we have a duplicate
}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.