Hi I have put up my code now and apologies for not doing it earlier, I was using a different computer and browser over the weekend, didnt have the compiler etc.
I tried to create a program that ask the user for Random numbers and generates non repeating numbers. It also asks for a file to store them in. I stayed up all night but no solution, Please help
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int main()
{
srand(unsigned(time(NULL)));
ifstream inputFile;
string theFile;
int numOfValues;
int values = 1 + rand() % 20; /****this is used to give the range of the
numbers to be generated******/
cout << "Select a file to open with its extension: ";
cin >> theFile;
cout << "How many random numbers do you want to generate: ";
cin >> numOfValues;
inputFile.open(theFile.c_str());
(Disch)... The problem is that the program repeats the numbers and that's the opposite of what I expect.
(Vlad).... In what way can I use either of it.
For example if you will use std::bitset you can set a corresponding bit for a given random number in the range [ 0, 19 ] or [ 1, 20 ].
for example
1 2 3 4 5 6 7 8 9 10
constint N = 20;
std::bitset<N> b;
do
{
values = 1 + rand() % N;
} while ( b[values - 1] );
b.set( values - 1 );
Also you should take into acccount that if you will try to get more that 20 random numbers you can get infinite loop because there is no free slot in the bitset. You shall reset it to get the second sequence of unique random numbers.