Mantorok said:
Not sure if this is possible, but is there some way to randomize a set
of integers from 0 to n(more specifically 0 to 100 inclusive) without
using rand() and in standard C?
/* BEGIN new.c */
#include <stdio.h>
#include <stdlib.h>
/**
#define LU_RAND_SEED (long unsigned)time(0)
/*/
#define LU_RAND_SEED 123456789LU
/**/
#define LU_RAND(S) ((S) = 69069 * (S) + 362437)
#define CARDS_IN_DECK 101
void shuffle(int *, int, long unsigned*);
int main(void)
{
int deck[CARDS_IN_DECK] = {0};
long unsigned seed = LU_RAND_SEED;
int counter;
shuffle(deck, CARDS_IN_DECK, &seed);
counter = CARDS_IN_DECK;
while (counter--) {
printf("%d\n", deck[counter]);
}
return 0;
}
void shuffle(int *array, int n, long unsigned* seed)
{
int i, r;
for (i = 1; n > i; ++i) {
r = LU_RAND(*seed) % (i + 1);
array
= array[r];
array[r] = i;
}
}
/* END new.c */