Generating Unique Random Numbers?
Okay guys, here is a problem I'm having. I have an array and I want to generate 10 random integers that dont overlap between 1 and 25. This is what I have but it keeps overlapping. Any Ideas?
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main(){
int question[9];
unsigned seed = time(NULL);
srand(seed);
for(int i=0; i < 10; i++){
question[i]=0;
}
for(int i=0; i < 10; i++){
question[i] = rand()/100%(10)+ 1;
//rand();
for(int x=0; x < 10; x++){
if(i==x) continue;
else{
while(question[i]==question[x]){
question[i] = rand()/100%(10)+ 1;
}
}
}
cout << question[i] << endl;
}
getch();
}

. I mainly just inserted the LinearSearch function and replaced one of your for loops with the for loop Infarction fixed. Just google "c++ unique random numbers" and I got it from the first result. Anyway here it is