Generating Random numbers

HERE IS THE PROBLEM :
Code a class named “TargetGen” that does the following:
 Generates a certain maximum number of random numbers that contains a certain number of
digits
 Gets from the user, the maximum number of random numbers that should be generated
 Gets from the user, the number of digits that each random number should contain
 Ensures that each random number is unique – in other words, none of the random numbers
are repeated
 Displays the entire “list” of random numbers in a nice, neat fashion
 You may use an array to store the random instances
 You may use strings as part of this number generating process
When you are done with the assignment there should be three self-written files, consisting of:
These files:
RVTARGETS.CPP, TARGETGEN.H and TARGETGEN.CPP
*********************************************************************

I couldn't figure how to generate unique random numbers and how to prompt the user for the number generating process.

Pleaaaseeee help
Here's an attempt to generate unique random numbers. It's an example for 10 numbers with 3 digits. Change all as you wish. The rest of the stuff...do yourself... ;D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>   
#include <numeric>	//  for iota
#include <algorithm>//	for random-shuffle

int main()
{
	int init = 100;
	int array[10];
	std::iota (array, array + 10, init);	//generate a sequence 
	std::cout << "Generated array: \n";	//of 10 numbers(3 digits!)
	for (int i : array)
		std::cout << ' ' << i;
	std::cout << "\n\n";
	std::cout << "Random array : \n";		 
	std::random_shuffle(array, array + 10);	//randomly rearrange
	for (int i : array)
		std::cout << ' ' << i;
	return 0;
}
Generated array: 
 100 101 102 103 104 105 106 107 108 109

Random array : 
 104 103 107 108 100 105 102 101 106 109
Last edited on
Topic archived. No new replies allowed.