#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define S 11
static int a[S];
static int maxn = S – 1;
void unique_rand_init() {
for (int i = 0; i < S; i++)
a[i] = i;
}
int unique_rand() {
int ran = rand() % (maxn + 1);
int r = a[ran];
int tmp = a[maxn];
a[maxn] = a[ran];
a[ran] = tmp;
if (–maxn < 0)
maxn = S – 1;
return r;
}
int main() {
srand(time(NULL));
unique_rand_init();
for (int i = 0; i < 11; i++)
printf(“%d \n”, unique_rand());
system(“pause”);
}