random numbers

I have a problem and i need some help. The program must print out 5 random numbers , from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same.... any ideas ?

for example

1,2,3,4,5
6,7,8,9,10
....
...
..

here is my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <ctime> 
#include <cstdlib> 

using namespace std;

int main ()
{
	int xRan1;
	
	srand( time(0)); 
	
	for (int j =0; j <100; j++) {  
		
	for (int i =0; i <5;  i++){ 
	xRan1=rand()%45+1;
        cout <<" " <<xRan1<<",";
		}
		
	cout << endl;
		}
	
	return 0;
}
While not enough numbers in set:
1. Generate a number
2. If it is already in the set, then discard, otherwise add to the set

Print the complete set
If you want to have unique numbers per sequence, then you only have 9 combinations, but if you want unique sequences then there are 1,221,759 different combinations:

http://en.wikipedia.org/wiki/Combination
Last edited on
Topic archived. No new replies allowed.