/* shuffle.c 配列撹拌ルーチン */
#include <stdio.h>
#include <string.h>
#include "random.h"
void shuffle_i(int *a, int n, long seed)
{
int i, m, *p, *q, w;
init_ornd2(seed);
for(i = 0, m = n * 5; i < m; i++)
{
p = a + (int)(ornd2() * n);
q = a + (int)(ornd2() * n);
w = *p;
*p = *q;
*q = w;
}
}
void shuffle_d(double *a, int n, long seed)
{
int i, m;
double *p, *q, w;
init_ornd2(seed);
for(i = 0, m = n * 5; i < m; i++)
{
p = a + (int)(ornd2() * n);
q = a + (int)(ornd2() * n);
w = *p;
*p = *q;
*q = w;
}
}
void shuffle_c(unsigned char **a, int n, long seed)
{
int i, m;
unsigned char **p, **q, *w;
init_ornd2(seed);
for(i = 0, m = n * 5; i < m; i++)
{
p = a + (int)(ornd2() * n);
q = a + (int)(ornd2() * n);
w = *p;
*p = *q;
*q = w;
}
}
|