/* * 'test-kolmogorov-smirnov.c' created: Sun Oct 20 22:42:00 2002 * * Copyright 2002 by Lubomir Host 'rajo' <8host AT pauli.fmph.uniba.sk> * * License: GNU GPL (GNU Public License) * */ /* $Platon$ */ #include #include #include #include #include "main.h" #include "devices.h" #include "tests.h" #include "test-kolmogorov-smirnov.h" RNG_test_t RNG_test_kolmog = { "Kolmogorov - Smirnov test of generators", 2E9, test_kolmog }; #define maximum(a, b) (((a) > (b)) ? (a) : (b)) int test_kolmog(int *counts) { int j = 0, k; int retval = RNG_OK; unsigned int cells; int *n_i; while (rng_devices[j] != NULL) { int i = 0; int cur = 1; int end = counts[0]; int index = 0; Real_t random; Real_t Z = 0.0; Real_t n_avg = 0.0; Real_t max = 0.0; printf("# @@ running test for R.N.G. %s\n", (*rng_devices[j]).desc); printf("# ** \n"); cells = ((unsigned int) (*rng_devices[j]).range >> (*rng_devices[j]).cell_count); n_i = calloc(cells, sizeof(int)); if (n_i == NULL) { fprintf(stderr, "Allocation of %d int's failed!\n", cells); return RNG_FAIL; } /* else { fprintf(stderr, "Allocating of %d int's OK\n", cells); } */ while (counts[i] != -1 && end != -1 && counts[i] <= RNG_test_kolmog.max_count && counts[i] <= (*rng_devices[j]).max_count && retval == RNG_OK) { end = counts[i]; while ((cur - 1) != end && end != -1) { /* printf("cur = %d end = %d\n", cur, end); */ random = (*rng_devices[j]).read(); if ((*rng_devices[j]).cell_count != 0) index = (unsigned int) random >> (*rng_devices[j]).cell_count; else index = (unsigned int) random; /* if (j==1) printf("random = %Lg\trandom_int = %d\tindex = %d\t\n", random, (int) random, index); */ n_i[index]++; /* increment counter for this cell */ /* if (j==1) printf("Incremented n_i[%d] = %d\n", index, n_i[index]); */ cur++; } /* here we are looking for parameter * Z = Sqrt(n) * Max(Abs(S_n(x) - F(x))) */ Z = 0.0; n_avg = (1.0 * counts[i]) / cells; max = 0.0; for (k = 0; k < cells; k++) { Real_t tmp; tmp = (n_i[k] > n_avg ? (n_i[k] - n_avg) : (n_avg - n_i[k])); /* if (tmp > max) printf("%Lg > %Lg n_i[%d] = %d n_avg = %Lg\n", tmp, max, k, n_i[k], n_avg); */ max = maximum(max, tmp); } Z = sqrt(counts[i]) * max; printf("%d\t%Lg\n", counts[i], Z); end = counts[++i + 1]; } j++; /* go to the next device ... */ free(n_i); } return retval; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=3: * }}} */