rand/srand urandom などを使用せずに、52 枚の標準カードのランダム配信をシミュレートしたい...
これは私の乱数関数です
int rand2(int lim)
{
static int a = 34; // could be made the seed value
a = (a * 32719 + 3) % 32749;
return ((a % lim) + 1);
}
カードがすでにポップされているかどうかを知る構造体 (0 = いいえ、1 はい)
typedef struct s_game
{
int *cards;
int state;
unsigned int dat_rand;
} t_game;
int main()
{
t_game game;
int i;
int rd;
i = 0;
game.cards = malloc(sizeof(*game.cards) * 52);
while(i < 52)
{
rd = rand2(52);
if(game.cards[rd] == 0)
{
game.cards[rd] = 1;
printf("i:%d\n rd: %d\n", i, rd);
i++;
}
}
}
しかし、私の出力は常に同じです。各カードは同時に配信されるため、より良いランダム関数または配信を満たす別の方法を探しています