- A C library for programming cognitive experiments on Windows
/* __ / /_______________ ____ ___ / __/ ___/ ___/ __ \/ __ \/ _ \ / /_(__ ) /__/ /_/ / /_/ / __/ \__/____/\___/\____/ .___/\___/ /_/ random1.c making a balanced design */ #include <tscope.h> // number of cells for each variable #define V1 2 #define V2 3 #define V3 2 // number of cells in the design #define CELLS (V1*V2*V3) // frequency of each cell #define FREQ 2 // data structure with the values // of the 3 variables on each trial struct { int v1, v2, v3; } data[CELLS * FREQ]; // randomize it int main() { int i, list[CELLS * FREQ]; // array with temporary values ts_rlist(CELLS, FREQ, list); // fill the array with random values // use the random trial number to compute // the values of the three variables printf("\n trn rnd v1 v2 v3 rnd\n"); for (i = 0; i < CELLS * FREQ; i++) { int tmp = list[i]; // take the random value printf(" %3d %3d ", i, tmp); // print trial number + random value data[i].v1 = tmp % V1; // remainder after division by V1 = level v1 tmp = list[i] / V1; // work on with the integer quotient data[i].v2 = tmp % V2; // remainder after division by V2 = level v2 tmp = tmp / V2; // work on with the integer quotient data[i].v3 = tmp % V3; // remainder after division by V3 = level v3 printf("%d ", data[i].v1); printf("%d ", data[i].v2); printf("%d ", data[i].v3); // reconstuction of the random value // shows that the derived values for the 3 variables // are unique tmp = data[i].v1 + data[i].v2 * V1 + data[i].v3 * V1 * V2; printf("%3d\n", tmp); } return 0; } END_OF_MAIN();