I'm trying to generate random numbers without any duplicate, like from 1 to 5 I want it to be 2 3 1 5 4 not 2 2 2 1 5. I've tried it but something went wrong and the code didn't work properly.
#include <stdlib.h>
#include <time.h>
int random(int minN, int maxN){
return minN + rand() % (maxN + 1 - minN);
}
int main(){
int max,min;
printf("nhap max ");
scanf("%d", &max);
printf("nhap min ");
scanf("%d", &min);
srand((int)time(0));
for (int i = 0; i < max; i++)
{
int arr[100];
arr[i] = random(min,max);
if(i!=0){
for(int j=i-1; j>=0;j-1){
if (arr[i]==arr[j])
continue;
}
}
printf("%d ",arr[i]);
}
}