├── NEWS ├── dieharder ├── dct-g207g208g14g205-n8 ├── dct-g207g208g14g205-Y2-k2 ├── Makefile.RDH ├── dump ├── validate.sh ├── validate.dat.old ├── d_g207_a.out ├── copyright.h ├── configure.ac ├── dieharder_exit.c ├── rng_empty_random.c ├── list_rand.c ├── output.h ├── time_rng.c ├── add_ui_rngs.c ├── add_ui_tests.c ├── user_template.h ├── dieharder.h ├── Makefile.am ├── validate_1000.sh ├── set_globals.c └── list_tests.c ├── libdieharder ├── libdieharder.svn.time ├── configure.ac ├── prob.c ├── timing.c ├── copyright.h ├── rng_stdin_input_raw.c ├── rng_jenkins.c ├── rgb_timing.c ├── Xtest.c ├── rng_dev_random.c ├── rng_dev_urandom.c ├── rng_dev_arandom.c ├── version.c ├── marsaglia_tsang_gorilla.c ├── random_seed.c ├── bauer │ ├── rijndael-alg-fst.h │ ├── rng_aes.c │ └── rng_threefish.c ├── convertoperm.pl ├── rgb_persist.c ├── rng_XOR.c ├── rng_aes.c ├── sample.c ├── rgb_kstest_test.c ├── histogram.c ├── diehard_3dsphere.c ├── dab_monobit2.c ├── dab_bytedistrib.c ├── sts_runs.c ├── rng_kiss.c ├── rgb_lagged_sums.c ├── diehard_rank_6x8.c └── rng_superkiss.c ├── .gitignore ├── dieharder.php ├── manual ├── example_ascii.input ├── configure.ac ├── dieharder.out ├── Makefile.am └── crown_quarto.tex ├── .github └── workflows │ └── c-cpp.yml ├── dieharder_version.h.in ├── include ├── dieharder │ ├── Xtest.h │ ├── marsaglia_tsang_gorilla.h │ ├── rgb_lmn.h │ ├── sts_monobit.h │ ├── dab_monobit2.h │ ├── copyright.h │ ├── parse.h │ ├── Dtest.h │ ├── diehard_squeeze.h │ ├── Vtest.h │ ├── rgb_timing.h │ ├── rgb_permutations.h │ ├── sts_runs.h │ ├── diehard_rank_32x32.h │ ├── diehard_oqso.h │ ├── diehard_rank_6x8.h │ ├── diehard_parking_lot.h │ ├── diehard_dna.h │ ├── diehard_3dsphere.h │ ├── diehard_craps.h │ ├── dab_filltree.h │ ├── rgb_operm.h │ ├── dab_bytedistrib.h │ ├── diehard_opso.h │ ├── diehard_2dsphere.h │ ├── rgb_bitdist.h │ ├── dab_filltree2.h │ ├── diehard_runs.h │ ├── verbose.h │ ├── rgb_kstest_test.h │ ├── diehard_count_1s_stream.h │ ├── diehard_sums.h │ ├── std_test.h │ ├── rgb_persist.h │ ├── diehard_birthdays.h │ ├── diehard_bitstream.h │ ├── dab_dct.h │ ├── marsaglia_tsang_gcd.h │ ├── rijndael-alg-fst.h │ ├── brg_endian.h │ ├── rgb_minimum_distance.h │ ├── dieharder_test_types.h │ ├── rgb_lagged_sums.h │ ├── diehard_count_1s_byte.h │ ├── dab_opso2.h │ ├── dab_birthdays1.h │ ├── sts_serial.h │ ├── tests.h │ └── dieharder_rng_types.h └── Makefile.am ├── README.md ├── Copyright ├── m4 └── ltversion.m4 ├── AUTHORS ├── dieharder-config.in ├── autogen.sh └── config.h.in /NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dieharder/dct-g207g208g14g205-n8: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dieharder/dct-g207g208g14g205-Y2-k2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libdieharder/libdieharder.svn.time: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | /autom4te.cache/ 5 | /config.* 6 | /configure 7 | /depcomp 8 | /install-sh 9 | /libtool 10 | /ltmain.sh 11 | /m4/ 12 | /missing 13 | /stamp-h? 14 | .deps/ 15 | .dirstamp 16 | .libs/ 17 | *.l[ao] 18 | *.o 19 | *~ 20 | *.bak 21 | -------------------------------------------------------------------------------- /dieharder.php: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /dieharder/Makefile.RDH: -------------------------------------------------------------------------------- 1 | 2 | PKG_CFLAGS = -g -W -I. -DRDIEHARDER 3 | PKG_LIBS = -ldieharder -lgsl -lgslcblas -lm 4 | 5 | sources := $(wildcard *.c) 6 | 7 | objects := $(sources:%.c=%.o) 8 | 9 | all : RDieHarder.so 10 | 11 | RDieHarder.so : $(objects) 12 | $(CC) -shared -o $@ $(objects) $(PKG_LIBS) 13 | 14 | clean : 15 | rm $(objects) RDieHarder.so 16 | -------------------------------------------------------------------------------- /dieharder/dump: -------------------------------------------------------------------------------- 1 | #================================================================== 2 | # generator mt19937 seed = 1350020181 3 | #================================================================== 4 | type: d 5 | count: 10 6 | numbit: 32 7 | 3313802016 8 | 2335490399 9 | 3384805761 10 | 904134280 11 | 1934989947 12 | 4103833375 13 | 2995980466 14 | 266194737 15 | 3877092254 16 | 3577442237 17 | -------------------------------------------------------------------------------- /manual/example_ascii.input: -------------------------------------------------------------------------------- 1 | #================================================================== 2 | # generator mt19937_1999 seed = 3022359314 3 | #================================================================== 4 | type: d 5 | count: 10 6 | numbit: 32 7 | 3918167916 8 | 1483868040 9 | 2886294571 10 | 1820144487 11 | 3098900874 12 | 3564305042 13 | 2601418103 14 | 1958443454 15 | 1831934296 16 | 1895780536 17 | -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: autogen.sh 15 | run: ./autogen.sh 16 | - name: configure 17 | run: ./configure 18 | - name: make 19 | run: make 20 | - name: make check 21 | run: make check 22 | # - name: make distcheck 23 | # run: make distcheck 24 | -------------------------------------------------------------------------------- /dieharder_version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef __GSL_VERSION_H__ 2 | #define __GSL_VERSION_H__ 3 | 4 | #include 5 | 6 | #undef __BEGIN_DECLS 7 | #undef __END_DECLS 8 | #ifdef __cplusplus 9 | # define __BEGIN_DECLS extern "C" { 10 | # define __END_DECLS } 11 | #else 12 | # define __BEGIN_DECLS /* empty */ 13 | # define __END_DECLS /* empty */ 14 | #endif 15 | __BEGIN_DECLS 16 | 17 | 18 | #define GSL_VERSION "@VERSION@" 19 | 20 | GSL_VAR const char * gsl_version; 21 | 22 | __END_DECLS 23 | 24 | #endif /* __GSL_VERSION_H__ */ 25 | -------------------------------------------------------------------------------- /dieharder/validate.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # This is the standard validation run for the current (3.x) working 4 | # snapshot of dieharder. I'm going to start keeping this and its output 5 | # in this directory under svn 6 | 7 | # Generic Tmpfile plus automagic cleanup. 8 | Tmpfile=$0.$$ 9 | trap 'rm $Tmpfile > /dev/null 2>&1; exit 0' 0 1 2 3 15 10 | 11 | ./dieharder -g 206 -S 1 -s 1 -m 10 -a | tee $Tmpfile 12 | 13 | echo "Validating against standard validate.dat" 14 | diff validate.dat $Tmpfile 15 | echo "Done!" 16 | mv validate.dat validate.dat.old 17 | cp $Tmpfile validate.dat 18 | -------------------------------------------------------------------------------- /manual/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) 6 | 7 | # Checks for programs. 8 | AC_PROG_MAKE_SET 9 | 10 | # Checks for libraries. 11 | # FIXME: Replace `main' with a function in `-local_icons': 12 | AC_CHECK_LIB([ocal_icons], [main]) 13 | 14 | # Checks for header files. 15 | 16 | # Checks for typedefs, structures, and compiler characteristics. 17 | 18 | # Checks for library functions. 19 | 20 | AC_CONFIG_FILES([Makefile]) 21 | AC_OUTPUT 22 | -------------------------------------------------------------------------------- /dieharder/validate.dat.old: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # dieharder version 3.29.6beta Copyright 2003 Robert G. Brown # 3 | #=============================================================================# 4 | rng_name |rands/second| 5 | AES_OFB| 2.89e+07 | 6 | #=============================================================================# 7 | test_name |ntup| tsamples |psamples| p-value |Assessment| Seed 8 | #=============================================================================# 9 | diehard_birthdays| 0| 100| 1000|0.48735022| PASSED | 1 10 | -------------------------------------------------------------------------------- /include/dieharder/Xtest.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: Btest.c 212 2006-07-21 18:07:33Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | /* 10 | * This is the struct used in Xtest.c, a erfc based test that generates 11 | * a p-value for a single normally distributed statistic. 12 | */ 13 | typedef struct { 14 | unsigned int npts; 15 | double p; 16 | double x; 17 | double y; 18 | double sigma; 19 | double pvalue; 20 | } Xtest; 21 | 22 | void Xtest_eval(Xtest *xtest); 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## dieharder 3 | 4 | ### Status 5 | 6 | This is the maintenance "upstream" repo to regroup updates made for the 7 | [Debian package dieharder](https://tracker.debian.org/pkg/dieharder). 8 | 9 | The repo was spawned off the [Debian package 10 | repo](https://salsa.debian.org/edd/dieharder) and contains its full history, 11 | which includes the full package history as well. 12 | 13 | There is another repo [containing mostly Robert's 14 | work](https://github.com/eddelbuettel/dieharder-rgb) as transfered from the 15 | old Google Code SVN repo. 16 | 17 | ### Maintainer 18 | 19 | Dirk Eddelbuettel 20 | 21 | ### Authors 22 | 23 | Robert G. Brown, Dirk Eddelbuettel, David Bauer 24 | -------------------------------------------------------------------------------- /dieharder/d_g207_a.out: -------------------------------------------------------------------------------- 1 | Seeding kiss 2 | Done! 3 | Seeding kiss 4 | Done! 5 | Seeding kiss 6 | Done! 7 | #=============================================================================# 8 | # dieharder version 3.29.5beta Copyright 2003 Robert G. Brown # 9 | #=============================================================================# 10 | rng_name |rands/second| Seed | 11 | kiss| 1.66e+08 | 969302850| 12 | #=============================================================================# 13 | test_name |ntup| tsamples |psamples| p-value |Assessment 14 | #=============================================================================# 15 | sts_monobit| 1| 100000| 100|0.00000000| FAILED 16 | -------------------------------------------------------------------------------- /Copyright: -------------------------------------------------------------------------------- 1 | /* 2 | * dieharder 3 | * 4 | * Copyright (c) 2007 by Robert G. Brown, rgb@phy.duke.edu 5 | * GPL version 2b (b for beverage) granted as given 6 | * in the file COPYING in this distribution. 7 | * 8 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 9 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 10 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 11 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 12 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 13 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | * 16 | */ 17 | 18 | -------------------------------------------------------------------------------- /dieharder/copyright.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: copyright.h 256 2007-01-27 15:14:15Z rgb $ 3 | * 4 | * Copyright (c) 2003 by Robert G. Brown, rgb@phy.duke.edu 5 | * GPL version 2b (b for beverage) granted as given 6 | * in the file COPYING in this distribution. 7 | * 8 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 9 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 10 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 11 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 12 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 13 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | * 16 | */ 17 | 18 | -------------------------------------------------------------------------------- /include/dieharder/marsaglia_tsang_gorilla.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hopefully this is a valid default initialization of the template test. 3 | */ 4 | 5 | static Dtest marsaglia_tsang_gorilla_data = { 6 | "Marsaglia and Tsang Gorilla Test", 7 | "\n\ 8 | #==================================================================\n\ 9 | # Marsaglia and Tsang Gorilla Test\n\ 10 | #\n\ 11 | # THIS TEST IS UNDER CONSTRUCTION! It does not work yet, and what\n\ 12 | # is presented is, in fact, the output of the test template.\n\ 13 | # Note that the second revision number will bump by one when this\n\ 14 | # test is completed -- check back later!\n\ 15 | #==================================================================\n", 16 | 100, 17 | 100000 18 | }; 19 | 20 | static Dtest *dtest = &marsaglia_tsang_gorilla_data; 21 | -------------------------------------------------------------------------------- /include/dieharder/rgb_lmn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hopefully this is a valid default initialization of the template test. 3 | */ 4 | 5 | int rgb_lmn(Dtest **dtest,Test **test); 6 | 7 | static Dtest lmn_test = { 8 | "RGB lmn Test", 9 | "rgb_lmn_test", 10 | "\n\ 11 | #==================================================================\n\ 12 | # RGB lmn Test\n\ 13 | #\n\ 14 | # This is a template for a Universal Test (of sorts) that replaces\n\ 15 | # or subsumes sts_series and rgb_bitdist. It should prove to be\n\ 16 | # a very powerful way of revealing bitlevel correlations and indeed\n\ 17 | # should systematically subsume many other tests as well.\n\ 18 | #==================================================================\n", 19 | 100, 20 | 100000 21 | 0, 22 | rgb_lmn, 23 | 0 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2019, 2021-2022 Free Software Foundation, 4 | # Inc. 5 | # Written by Scott James Remnant, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # @configure_input@ 12 | 13 | # serial 4245 ltversion.m4 14 | # This file is part of GNU Libtool 15 | 16 | m4_define([LT_PACKAGE_VERSION], [2.4.7]) 17 | m4_define([LT_PACKAGE_REVISION], [2.4.7]) 18 | 19 | AC_DEFUN([LTVERSION_VERSION], 20 | [macro_version='2.4.7' 21 | macro_revision='2.4.7' 22 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 23 | _LT_DECL(, macro_revision, 0) 24 | ]) 25 | -------------------------------------------------------------------------------- /include/dieharder/sts_monobit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sts_monobit test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int sts_monobit(Test **test,int irun); 9 | 10 | static Dtest sts_monobit_dtest __attribute__((unused)) = { 11 | "STS Monobit Test", 12 | "sts_monobit", 13 | "\ 14 | #==================================================================\n\ 15 | # STS Monobit Test\n\ 16 | # Very simple. Counts the 1 bits in a long string of random uints.\n\ 17 | # Compares to expected number, generates a p-value directly from\n\ 18 | # erfc(). Very effective at revealing overtly weak generators;\n\ 19 | # Not so good at determining where stronger ones eventually fail.\n\ 20 | #==================================================================\n", 21 | 100, 22 | 100000, 23 | 1, 24 | sts_monobit, 25 | 0 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /libdieharder/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_CONFIG_SRCDIR([rgb_persist.c]) 6 | AC_CONFIG_HEADER([config.h]) 7 | AM_INIT_AUTOMAKE([-Wall]) 8 | 9 | # Checks for programs. 10 | AC_PROG_CC 11 | AC_PROG_INSTALL 12 | 13 | # Checks for libraries. 14 | AC_CHECK_LIB([gslcblas], [cblas_ddot]) 15 | AC_CHECK_LIB([gsl], [gsl_error]) 16 | 17 | # Checks for header files. 18 | AC_HEADER_STDC 19 | AC_CHECK_HEADERS([string.h]) 20 | 21 | # Checks for typedefs, structures, and compiler characteristics. 22 | AC_C_CONST 23 | AC_TYPE_SIZE_T 24 | AC_HEADER_TIME 25 | 26 | # Checks for library functions. 27 | AC_FUNC_MALLOC 28 | AC_FUNC_STAT 29 | AC_CHECK_FUNCS([bzero gettimeofday memset pow sqrt]) 30 | 31 | AC_CONFIG_FILES([Makefile]) 32 | AC_OUTPUT 33 | -------------------------------------------------------------------------------- /include/dieharder/dab_monobit2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_monobit2 test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_monobit2(Test **test,int irun); 9 | 10 | static Dtest dab_monobit2_dtest __attribute__((unused)) = { 11 | "DAB Monobit 2 Test", 12 | "dab_monobit2", 13 | "\ 14 | #==================================================================\n\ 15 | # DAB Monobit 2 Test\n\ 16 | # Block-monobit test.\n\ 17 | # Since we don't know what block size to use, try multiple block\n\ 18 | # sizes. In particular, try all block sizes of 2^k words, where\n\ 19 | # k={0..n}. The value of n is calculated from the word size of the\n\ 20 | # generator and the sample size used, and is shown as ntuple.\n\ 21 | #==================================================================\n", 22 | 1, 23 | 65000000, 24 | 1, 25 | dab_monobit2, 26 | 0 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /dieharder/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_CONFIG_SRCDIR([run_diehard_dna.c]) 6 | AC_CONFIG_HEADER([config.h]) 7 | AM_INIT_AUTOMAKE([-Wall]) 8 | 9 | # Checks for programs. 10 | AC_PROG_CC 11 | AC_PROG_INSTALL 12 | 13 | # Checks for libraries. 14 | AC_CHECK_LIB([gslcblas], [cblas_ddot]) 15 | AC_CHECK_LIB([gsl], [gsl_error]) 16 | 17 | # Checks for header files. 18 | AC_HEADER_STDC 19 | AC_CHECK_HEADERS([limits.h stdlib.h string.h sys/time.h unistd.h]) 20 | 21 | # Checks for typedefs, structures, and compiler characteristics. 22 | AC_C_CONST 23 | AC_TYPE_SIZE_T 24 | AC_HEADER_TIME 25 | 26 | # Checks for library functions. 27 | AC_FUNC_ERROR_AT_LINE 28 | AC_FUNC_MALLOC 29 | AC_FUNC_STRTOD 30 | AC_CHECK_FUNCS([sqrt strtol]) 31 | 32 | AC_CONFIG_FILES([Makefile]) 33 | AC_OUTPUT 34 | -------------------------------------------------------------------------------- /include/dieharder/copyright.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIEHARDER_COPYRIGHT_H_ 2 | #define _DIEHARDER_COPYRIGHT_H_ 3 | /* 4 | * $Id: copyright.h 222 2006-08-17 04:54:59Z rgb $ 5 | * 6 | * Copyright (c) 2003 by Robert G. Brown, rgb@phy.duke.edu 7 | * GPL version 2b (b for beverage) granted as given 8 | * in the file COPYING in this distribution. 9 | * 10 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 11 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 12 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 14 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 | * PERFORMANCE OF THIS SOFTWARE. 17 | * 18 | */ 19 | #endif /* _DIEHARDER_COPYRIGHT_H_ */ 20 | -------------------------------------------------------------------------------- /libdieharder/prob.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: prob.c 223 2006-08-17 06:19:38Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * 6 | */ 7 | 8 | /* 9 | *======================================================================== 10 | * timing and utility sources. tv_start and tv_stop are globals. 11 | *======================================================================== 12 | */ 13 | 14 | #include 15 | 16 | double binomial(unsigned int n, unsigned int k, double p) 17 | { 18 | 19 | double pnk; 20 | 21 | if(verbose > 10){ 22 | printf("binomial(): Making binomial p(%d,%d,%f)\n",n,k,p); 23 | } 24 | 25 | pnk = gsl_sf_fact(n)*pow(p,(double)k)*pow((1.0-p),(double)(n-k))/ 26 | (gsl_sf_fact(k)*gsl_sf_fact(n-k)); 27 | 28 | if(verbose > 10){ 29 | printf("binomial(): Made binomial p(%d,%d,%f) = %f\n",n,k,p,pnk); 30 | } 31 | 32 | return(pnk); 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /include/dieharder/parse.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * See copyright in copyright.h and the accompanying file COPYING 4 | *======================================================================== 5 | * Utility routines to support basic needs of the program like managing 6 | * models, creating and deleting directories with contents. Probable 7 | * cruft or yet-unused routines belong at the bottom... 8 | *======================================================================== 9 | */ 10 | 11 | 12 | /* 13 | * This is a somewhat sloppy way to do this, I suppose, but it will work 14 | */ 15 | #define PBUF 128 16 | #define PK 1024 17 | 18 | /* 19 | * Shared space 20 | */ 21 | extern char splitbuf[PK][PBUF]; 22 | 23 | /* 24 | * parse.c prototypes 25 | */ 26 | int split(char *inbuffer); 27 | int parse(char *inbuffer,char **outfields,int maxfields,int maxfieldlength); 28 | void chop(char *buf); 29 | -------------------------------------------------------------------------------- /libdieharder/timing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: timing.c 223 2006-08-17 06:19:38Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * 6 | */ 7 | 8 | /* 9 | *======================================================================== 10 | * timing and utility sources. tv_start and tv_stop are globals. 11 | *======================================================================== 12 | */ 13 | 14 | #include 15 | 16 | void start_timing() 17 | { 18 | gettimeofday(&tv_start, (struct timezone *) NULL); 19 | } 20 | 21 | void stop_timing() 22 | { 23 | gettimeofday(&tv_stop, (struct timezone *) NULL); 24 | } 25 | 26 | double delta_timing() 27 | { 28 | 29 | return((double)(tv_stop.tv_sec - tv_start.tv_sec) 30 | + 1.0e-6*(double)(tv_stop.tv_usec - tv_start.tv_usec)); 31 | } 32 | 33 | unsigned int makeseed() 34 | { 35 | struct timeval tv; 36 | gettimeofday(&tv,0); 37 | return tv.tv_sec + tv.tv_usec; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /dieharder/dieharder_exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: work.c 320 2007-05-21 13:34:44Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | #include "dieharder.h" 10 | 11 | /* 12 | *======================================================================== 13 | * We need a wrapper for exit() because we cannot call it in R. 14 | * We also very likely will need to do some cleanup on exit that 15 | * didn't bother with in dieharder on a single pass CL program -- 16 | * somebody might well run dieharder in a loop and leak otherwise. 17 | *======================================================================== 18 | */ 19 | 20 | void Exit(int exitcode) { 21 | 22 | #if !defined(RDIEHARDER) 23 | exit(exitcode); 24 | #endif /* !defined(RDIEHARDER) */ 25 | 26 | /* Add any e.g. free() statements below */ 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /dieharder/rng_empty_random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a wrapping of the /dev/random hardware rng 3 | */ 4 | 5 | #include "dieharder.h" 6 | 7 | 8 | static unsigned long int dev_random_get (void *vstate); 9 | static double dev_random_get_double (void *vstate); 10 | static void dev_random_set (void *vstate, unsigned long int s); 11 | 12 | typedef struct 13 | { 14 | } 15 | dev_random_state_t; 16 | 17 | static unsigned long int 18 | empty_random_get (void *vstate) 19 | { 20 | 21 | } 22 | 23 | static double 24 | empty_random_get_double (void *vstate) 25 | { 26 | return 0.0; 27 | } 28 | 29 | static void 30 | empty_random_set (void *vstate, unsigned long int s) 31 | { 32 | 33 | return; 34 | 35 | } 36 | 37 | static const gsl_rng_type empty_random_type = 38 | {"empty", /* name */ 39 | 0, /* RAND_MAX */ 40 | 0, /* RAND_MIN */ 41 | sizeof (dev_random_state_t), 42 | &empty_random_set, 43 | &empty_random_get, 44 | &empty_random_get_double}; 45 | 46 | const gsl_rng_type *gsl_rng_empty_random = &empty_random_type; 47 | -------------------------------------------------------------------------------- /include/dieharder/Dtest.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: libdieharder.h 221 2006-08-16 22:43:03Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | typedef struct { 10 | /* The name of the test */ 11 | char *name; 12 | 13 | /* The SHORT name of the test (its call name) */ 14 | char *sname; 15 | 16 | /* pointer to a test description */ 17 | char *description; 18 | 19 | /* Standard test default */ 20 | unsigned int psamples_std; 21 | 22 | /* Standard test default */ 23 | unsigned int tsamples_std; 24 | 25 | /* Number of independent statistics generated per run */ 26 | unsigned int nkps; 27 | 28 | /* A pointer to the test itself (must be filled at initialization) */ 29 | int (*test)(); 30 | 31 | /* void pointer to a vector of additional test arguments */ 32 | void *targs; 33 | 34 | } Dtest; 35 | 36 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Robert G. Brown 2 | Primary author and maintainer of RPM versions and original sources. 3 | 4 | Dirk Eddelbuettel 5 | Maintainer of Debian versions and contributor of the R interface. 6 | 7 | David Bauer 8 | Debugger and fixer extraordinaire, contributor of the aes and 9 | threefish "gold standard" rngs and major factor in the fixing of kstest 10 | so that it is now "exact". 11 | 12 | Many other individuals have contributed to dieharder at this point by 13 | pointing out bugs or probable errors, by contributing improved 14 | statistical targets or fragments of code or random number generators to 15 | add. I do not include a full list of their names here to protect them 16 | from the responsibilities of maintaining the code and their privacy, but 17 | I do try to acknowledge them in the actual code source that they've most 18 | affected. Please feel free to join the dieharder development mailing 19 | list at 20 | 21 | https://lists.phy.duke.edu/mailman/listinfo/dieharder-devel 22 | 23 | and participate. 24 | -------------------------------------------------------------------------------- /include/dieharder/diehard_squeeze.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_squeeze test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_squeeze(Test **test,int irun); 9 | 10 | static Dtest diehard_squeeze_dtest __attribute__((unused)) = { 11 | "Diehard Squeeze Test", 12 | "diehard_squeeze", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Squeeze Test.\n\ 16 | # Random integers are floated to get uniforms on [0,1). Start- \n\ 17 | # ing with k=2^31=2147483647, the test finds j, the number of \n\ 18 | # iterations necessary to reduce k to 1, using the reduction \n\ 19 | # k=ceiling(k*U), with U provided by floating integers from \n\ 20 | # the file being tested. Such j's are found 100,000 times, \n\ 21 | # then counts for the number of times j was <=6,7,...,47,>=48 \n\ 22 | # are used to provide a chi-square test for cell frequencies. \n\ 23 | #==================================================================\n", 24 | 100, 25 | 100000, 26 | 1, 27 | diehard_squeeze, 28 | 0 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /include/dieharder/Vtest.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: Btest.c 212 2006-07-21 18:07:33Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | /* 10 | * This is the struct used in Vtest.c, a standard Pearson's chisq 11 | * test on a vector of measurements and corresponding expected 12 | * mean values. 13 | */ 14 | typedef struct { 15 | unsigned int nvec; /* Length of x,y vectors */ 16 | unsigned int ndof; /* Number of degrees of freedom, default nvec-1 */ 17 | double cutoff; /* y has to be greater than this to be included */ 18 | double *x; /* Vector of measurements */ 19 | double *y; /* Vector of expected values */ 20 | double chisq; /* Resulting Pearson's chisq */ 21 | double pvalue; /* Resulting p-value */ 22 | } Vtest; 23 | 24 | void Vtest_create(Vtest *vtest, unsigned int nvec); 25 | void Vtest_destroy(Vtest *vtest); 26 | void Vtest_eval(Vtest *vtest); 27 | 28 | -------------------------------------------------------------------------------- /libdieharder/copyright.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: copyright.h 2 2003-01-12 00:07:56Z rgb $ 3 | * 4 | * Copyright (c) 2003 by Robert G. Brown, rgb@phy.duke.edu 5 | * GPL version 2b (b for beverage) granted as given 6 | * in the file COPYING in this distribution. 7 | * 8 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 9 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 10 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 11 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 12 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 13 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | * PERFORMANCE OF THIS SOFTWARE. 15 | * 16 | */ 17 | 18 | /* 19 | * This embeds the copyright/license strings into this application 20 | * where "strings libdieharder | grep Copyright" can find them, for 21 | * example. 22 | */ 23 | char copyright[] = "Copyright 2003 by Robert G. Brown, rgb@phy.duke.edu"; 24 | char license[] = "Gnu Public License version 2b (b for beverage)"; 25 | -------------------------------------------------------------------------------- /include/dieharder/rgb_timing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_rgb_timing test header. This is a nonstandard test and 3 | * returns no pvalues, and should probably be converted so that it 4 | * doesn't LOOK like a test. 5 | */ 6 | 7 | /* 8 | * function prototype 9 | */ 10 | typedef struct { 11 | double avg_time_nsec; 12 | double rands_per_sec; 13 | } Rgb_Timing; 14 | int rgb_timing(Test **test, Rgb_Timing *timing); 15 | 16 | static Dtest rgb_timing_dtest __attribute__((unused)) = { 17 | "RGB Timing Test", 18 | "rgb_timing", 19 | "\ 20 | #========================================================================\n\ 21 | # RGB Timing Test\n\ 22 | #\n\ 23 | # This test times the selected random number generator only. It is\n\ 24 | # generally run at the beginning of a run of -a(ll) the tests to provide\n\ 25 | # some measure of the relative time taken up generating random numbers\n\ 26 | # for the various generators and tests.\n\ 27 | ", 28 | 10, /* Number of psamples (passes) */ 29 | 1000000, /* Number of samples in inner loop */ 30 | 1, /* Number of tests */ 31 | rgb_timing, 32 | 0 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /include/dieharder/rgb_permutations.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rgb_permutations test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int rgb_permutations(Test **test,int irun); 9 | 10 | static Dtest rgb_permutations_dtest __attribute__((unused)) = { 11 | "RGB Permutations Test", 12 | "rgb_permutations", 13 | "\n\ 14 | #========================================================================\n\ 15 | # RGB Permutations Test\n\ 16 | # This is a non-overlapping test that simply counts order permutations of\n\ 17 | # random numbers, pulled out n at a time. There are n! permutations\n\ 18 | # and all are equally likely. The samples are independent, so one can\n\ 19 | # do a simple chisq test on the count vector with n! - 1 degrees of\n\ 20 | # freedom. This is a poor-man's version of the overlapping permutations\n\ 21 | # tests, which are much more difficult because of the covariance of the\n\ 22 | # overlapping samples.\n\ 23 | #\n", 24 | 100, /* Default psamples */ 25 | 100000, /* Default tsamples */ 26 | 1, /* We magically make all the bit tests return a single histogram */ 27 | rgb_permutations, 28 | 0 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /include/dieharder/sts_runs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sts_runs test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int sts_runs(Test **test,int irun); 9 | 10 | static Dtest sts_runs_dtest __attribute__((unused)) = { 11 | "STS Runs Test", 12 | "sts_runs", 13 | "\ 14 | #==================================================================\n\ 15 | # STS Runs Test\n\ 16 | # Counts the total number of 0 runs + total number of 1 runs across\n\ 17 | # a sample of bits. Note that a 0 run must begin with 10 and end\n\ 18 | # with 01. Note that a 1 run must begin with 01 and end with a 10.\n\ 19 | # This test, run on a bitstring with cyclic boundary conditions, is\n\ 20 | # absolutely equivalent to just counting the 01 + 10 bit pairs.\n\ 21 | # It is therefore totally redundant with but not as good as the\n\ 22 | # rgb_bitdist() test for 2-tuples, which looks beyond the means to the\n\ 23 | # moments, testing an entire histogram of 00, 01, 10, and 11 counts\n\ 24 | # to see if it is binomially distributed with p = 0.25.\n\ 25 | #==================================================================\n", 26 | 100, 27 | 100000, 28 | 1, 29 | sts_runs, 30 | 0 31 | }; 32 | 33 | 34 | -------------------------------------------------------------------------------- /include/dieharder/diehard_rank_32x32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_rank_32x32 test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_rank_32x32(Test **test,int irun); 9 | 10 | static Dtest diehard_rank_32x32_dtest __attribute__((unused)) = { 11 | "Diehard 32x32 Binary Rank Test", 12 | "diehard_rank_32x32", 13 | "\n\ 14 | #==================================================================\n\ 15 | # Diehard 32x32 Binary Rank Test\n\ 16 | # This is the BINARY RANK TEST for 32x32 matrices. A random 32x\n\ 17 | # 32 binary matrix is formed, each row a 32-bit random integer.\n\ 18 | # The rank is determined. That rank can be from 0 to 32, ranks\n\ 19 | # less than 29 are rare, and their counts are pooled with those\n\ 20 | # for rank 29. Ranks are found for 40,000 such random matrices\n\ 21 | # and a chisquare test is performed on counts for ranks 32,31,\n\ 22 | # 30 and <=29.\n\ 23 | #\n\ 24 | # As always, the test is repeated and a KS test applied to the\n\ 25 | # resulting p-values to verify that they are approximately uniform.\n\ 26 | #==================================================================\n", 27 | 100, 28 | 40000, 29 | 1, 30 | diehard_rank_32x32, 31 | 0 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /include/dieharder/diehard_oqso.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_oqso test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_oqso(Test **test, int irun); 9 | 10 | static Dtest diehard_oqso_dtest __attribute__((unused)) = { 11 | "Diehard OQSO Test", 12 | "diehard_oqso", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Overlapping Quadruples Sparce Occupancy (OQSO) Test\n\ 16 | #\n\ 17 | # Similar, to OPSO except that it considers 4-letter \n\ 18 | # words from an alphabet of 32 letters, each letter determined \n\ 19 | # by a designated string of 5 consecutive bits from the test \n\ 20 | # file, elements of which are assumed 32-bit random integers. \n\ 21 | # The mean number of missing words in a sequence of 2^21 four- \n\ 22 | # letter words, (2^21+3 \"keystrokes\"), is again 141909, with \n\ 23 | # sigma = 295. The mean is based on theory; sigma comes from \n\ 24 | # extensive simulation. \n\ 25 | # \n\ 26 | # Note 2^21 = 2097152, tsamples cannot be varied.\n\ 27 | #==================================================================\n", 28 | 100, 29 | 2097152, 30 | 1, 31 | diehard_oqso, 32 | 0 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /dieharder-config.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | includedir=@includedir@ 6 | 7 | usage() 8 | { 9 | cat <21 are lumped with 21. \n\ 22 | # A chi-square test is made on the no.-of-throws cell counts. \n\ 23 | # Each 32-bit integer from the test file provides the value for \n\ 24 | # the throw of a die, by floating to [0,1), multiplying by 6 \n\ 25 | # and taking 1 plus the integer part of the result. \n\ 26 | #==================================================================\n", 27 | 100, /* Default psamples */ 28 | 200000, /* Default tsamples */ 29 | 2, /* This test returns two statistics */ 30 | diehard_craps, 31 | 0 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /include/dieharder/dab_filltree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_filltree test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_filltree(Test **test, int irun); 9 | 10 | static Dtest dab_filltree_dtest __attribute__((unused)) = { 11 | "DAB Fill Tree Test", 12 | "dab_filltree", 13 | "\ 14 | #==================================================================\n\ 15 | # DAB Fill Tree Test\n\ 16 | # This test fills small binary trees of fixed depth with\n\ 17 | # words from the the RNG. When a word cannot be inserted\n\ 18 | # into the tree, the current count of words in the tree is\n\ 19 | # recorded, along with the position at which the word\n\ 20 | # would have been inserted.\n\ 21 | #\n\ 22 | # The words from the RNG are rotated (in long cycles) to\n\ 23 | # better detect RNGs that may bias only the high, middle,\n\ 24 | # or low bytes.\n\ 25 | #\n\ 26 | # The test returns two p-values. The first is a Pearson\n\ 27 | # chi-sq test against the expected values (which were\n\ 28 | # estimated empirically). The second is a Pearson chi-sq\n\ 29 | # test for a uniform distribution of the positions at\n\ 30 | # which the insert failed.\n\ 31 | #\n\ 32 | # Because of the target data for the first p-value,\n\ 33 | # ntuple must be kept at the default (32).\n\ 34 | #==================================================================\n", 35 | 1, 36 | 15000000, 37 | 2, 38 | dab_filltree, 39 | 0 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /include/dieharder/rgb_operm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rgb_operm test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int rgb_operm(Test **test,int irun); 9 | 10 | static Dtest rgb_operm_dtest __attribute__((unused)) = { 11 | "RGB Overlapping Permuations Test", 12 | "rgb_operm", 13 | "\n\ 14 | #========================================================================\n\ 15 | # RGB Overlapping Permutations Test\n\ 16 | # Forms both the exact (expected) covariance matrix for overlapping\n\ 17 | # permutations of random integer and an empirical covariance matrix\n\ 18 | # formed from a long string of samples. The difference is expected\n\ 19 | # to have a chisq distribution and hence can be transformed into a\n\ 20 | # sample p-value. Note that this is one possible functional replacement\n\ 21 | # for the broken/defunct diehard operm5 test, but one that permits k (the\n\ 22 | # number of numbers in the overlapping permutation window) to be varied\n\ 23 | # from 2 to perhaps 8.\n\ 24 | #\n", 25 | 100, /* Default psamples */ 26 | 100000, /* Default tsamples */ 27 | 1, /* We magically make all the bit tests return a single histogram */ 28 | rgb_operm, 29 | 0 30 | }; 31 | 32 | /* 33 | * Global variables. 34 | * 35 | * rgb_operm_k is the size of the overlapping window that is slid along 36 | * a data stream of rands from x_i to x_{i+k} to compute c[][]. 37 | */ 38 | extern unsigned int rgb_operm_k; 39 | -------------------------------------------------------------------------------- /include/dieharder/dab_bytedistrib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_bytedistrib test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_bytedistrib(Test **test, int irun); 9 | 10 | static Dtest dab_bytedistrib_dtest __attribute__((unused)) = { 11 | "Byte Distribution", 12 | "dab_bytedistrib", 13 | "\ 14 | #==================================================================\n\ 15 | DAB Byte Distribution Test\n\ 16 | #\n\ 17 | # Extract n independent bytes from each of k consecutive words. Increment\n\ 18 | # indexed counters in each of n tables. (Total of 256 * n counters.)\n\ 19 | # Currently, n=3 and is fixed at compile time.\n\ 20 | # If n>=2, then the lowest and highest bytes will be used, along\n\ 21 | # with n-2 bytes from the middle.\n\ 22 | # If the generator's word size is too small, overlapped bytes will\n\ 23 | # be used.\n\ 24 | # Current, k=3 and is fixed at compile time.\n\ 25 | # Use a basic chisq fitting test (chisq_pearson) for the p-value.\n\ 26 | # Previous version also used a chisq independence test (chisq2d); it\n\ 27 | # was found to be slightly less sensitive.\n\ 28 | # I envisioned this test as using a small number of samples and large\n\ 29 | # number of separate tests. Experiments so far show that keeping -p 1\n\ 30 | # and increasing -t performs best.\n\ 31 | #==================================================================\n", 32 | 1, 33 | 51200000, 34 | 1, 35 | dab_bytedistrib, 36 | 0 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /dieharder/output.h: -------------------------------------------------------------------------------- 1 | /* 2 | * These are all binary flags, used to control precisely what comes out 3 | * of dieharder in its reports. The vector of strings immediately 4 | * below it can be used to match up names to the power of two of each 5 | * entry. Be sure to keep the two precisely in sync! 6 | */ 7 | typedef enum { 8 | TDEFAULT = 0, 9 | THEADER = 1, 10 | TSHOW_RNG = 2, 11 | TLINE_HEADER = 4, 12 | TTEST_NAME = 8, 13 | TNTUPLE = 16, 14 | TTSAMPLES = 32, 15 | TPSAMPLES = 64, 16 | TPVALUES = 128, 17 | TASSESSMENT = 256, 18 | TPREFIX = 512, 19 | TDESCRIPTION = 1024, 20 | THISTOGRAM = 2048, 21 | TSEED = 4096, 22 | TRATE = 8192, 23 | TNUM = 16384, 24 | TNO_WHITE = 32768, 25 | TPSAMPLE_VALS = 65536, 26 | TFILE_RNG_STAT = 131072 27 | } Table; 28 | 29 | #define TCNT 18 30 | 31 | /* 32 | * These should have a maximum length one can use in strncmp(). 33 | * At the moment it looks like 10, but I think 16 is a safer 34 | * bet (and still safe from a buffer overwrite point of view) 35 | */ 36 | #define TLENGTH 16 37 | static char *table_fields[] __attribute__((unused)) = { 38 | "default", 39 | "header", 40 | "show_rng", 41 | "line_header", 42 | "test_name", 43 | "ntuple", 44 | "tsamples", 45 | "psamples", 46 | "pvalues", 47 | "assessment", 48 | "prefix", 49 | "description", 50 | "histogram", 51 | "seed", 52 | "rate", 53 | "show_num", 54 | "no_whitespace", 55 | "psample_values", 56 | "file_rng_stat" 57 | }; 58 | -------------------------------------------------------------------------------- /libdieharder/rng_stdin_input_raw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * This is a wrapping of stdin. 8 | */ 9 | 10 | static unsigned long int stdin_input_raw_get (void *vstate); 11 | static double stdin_input_raw_get_double (void *vstate); 12 | static void stdin_input_raw_set (void *vstate, unsigned long int s); 13 | 14 | static unsigned long int 15 | stdin_input_raw_get (void *vstate) 16 | { 17 | unsigned int j; 18 | if (fread(&j,sizeof(j),1,stdin) != 1) { 19 | if (feof(stdin)) { 20 | fprintf(stderr,"# stdin_input_raw(): Error: EOF\n"); 21 | } else { 22 | fprintf(stderr,"# stdin_input_raw(): Error: %s\n", strerror(errno)); 23 | } 24 | exit(0); 25 | } 26 | /* printf("raw: %10u\n",j); */ 27 | return j; 28 | } 29 | 30 | static double 31 | stdin_input_raw_get_double (void *vstate) 32 | { 33 | return stdin_input_raw_get(vstate) / (double)UINT_MAX; 34 | } 35 | 36 | static void 37 | stdin_input_raw_set (void *vstate, unsigned long int s) 38 | { 39 | /* empty */ 40 | } 41 | 42 | static const gsl_rng_type stdin_input_raw_type = 43 | {"stdin_input_raw", /* name */ 44 | UINT_MAX, /* RAND_MAX */ 45 | 0, /* RAND_MIN */ 46 | 0, 47 | stdin_input_raw_set, 48 | stdin_input_raw_get, 49 | stdin_input_raw_get_double}; 50 | 51 | const gsl_rng_type *gsl_rng_stdin_input_raw = &stdin_input_raw_type; 52 | -------------------------------------------------------------------------------- /dieharder/time_rng.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: dieharder.c 127 2004-11-20 18:17:55Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | /* 10 | *======================================================================== 11 | * time_rng() times the CURRENT random number generator specified by 12 | * the global rng. Truthfully, most of the stuff below is unnecessary, 13 | * as rgb_timing() isn't a pvalue-generating test. I'll rewrite it 14 | * eventually, but it works fine as is for now. 15 | *======================================================================== 16 | */ 17 | 18 | #include "dieharder.h" 19 | 20 | void time_rng() 21 | { 22 | 23 | /* 24 | * Declare the results struct. 25 | */ 26 | Rgb_Timing timing; 27 | Test **rgb_timing_test; 28 | 29 | /* 30 | * First we create the test (to set some values displayed in test header 31 | * correctly). 32 | */ 33 | rgb_timing_test = create_test(&rgb_timing_dtest,tsamples,psamples); 34 | 35 | /* 36 | * Call the actual test that fills in the results struct. 37 | */ 38 | rgb_timing(rgb_timing_test,&timing); 39 | 40 | /* 41 | * Save this for display in 42 | */ 43 | rng_avg_time_nsec = timing.avg_time_nsec; 44 | rng_rands_per_second = timing.rands_per_sec; 45 | 46 | destroy_test(&rgb_timing_dtest,rgb_timing_test); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/dieharder/diehard_opso.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_opso test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_opso(Test **test, int irun); 9 | 10 | static Dtest diehard_opso_dtest __attribute__((unused)) = { 11 | "Diehard OPSO", 12 | "diehard_opso", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Overlapping Pairs Sparse Occupance (OPSO)\n\ 16 | # The OPSO test considers 2-letter words from an alphabet of \n\ 17 | # 1024 letters. Each letter is determined by a specified ten \n\ 18 | # bits from a 32-bit integer in the sequence to be tested. OPSO \n\ 19 | # generates 2^21 (overlapping) 2-letter words (from 2^21+1 \n\ 20 | # \"keystrokes\") and counts the number of missing words---that \n\ 21 | # is 2-letter words which do not appear in the entire sequence. \n\ 22 | # That count should be very close to normally distributed with \n\ 23 | # mean 141,909, sigma 290. Thus (missingwrds-141909)/290 should \n\ 24 | # be a standard normal variable. The OPSO test takes 32 bits at \n\ 25 | # a time from the test file and uses a designated set of ten \n\ 26 | # consecutive bits. It then restarts the file for the next de- \n\ 27 | # signated 10 bits, and so on. \n\ 28 | # \n\ 29 | # Note 2^21 = 2097152, tsamples cannot be varied.\n\ 30 | #==================================================================\n", 31 | 100, 32 | 2097152, 33 | 1, 34 | diehard_opso, 35 | 0 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /libdieharder/rng_jenkins.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This program uses the Jenkins One-at-a-Time hash function as a PRNG 3 | * by simulating the process of feeding it successively longer blocks 4 | * of all zeros. Each 32-bit hash value doubles as the pseudo-random 5 | * number which is written as binary on stdout in the byte order of 6 | * the machine. 7 | * 8 | * @file 9 | * @brief Jenkins One-at-a-Time hash function as PRNG 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | int 18 | main(int argc, 19 | char* argv[]) 20 | { 21 | int rv = 0; 22 | uint32_t a = 0xbb48e941; 23 | uint32_t b = 0; 24 | 25 | for (;;) { 26 | /* Inner loop of Jenkins One-at-a-Time hash function where the 27 | * next character is '\0'. */ 28 | a += '\0'; 29 | a += (a << 10); 30 | a ^= (a >> 6); 31 | 32 | /* Post-processing. */ 33 | b = a + (a << 3); 34 | b ^= (b >> 11); 35 | b += (b << 15); 36 | 37 | /* Write the hash value to stdout as binary in the byte order 38 | * of the machine. */ 39 | if (fwrite(&b, sizeof(b), 1, stdout) != 1) { 40 | if (feof(stdout)) { 41 | fprintf(stderr, "*** Error: fwrite: Unexpected EOF.\n"); 42 | } else { 43 | fprintf(stderr, "*** Error: fwrite: %s\n", strerror(errno)); 44 | } 45 | rv = 1; 46 | break; 47 | } 48 | } 49 | 50 | return rv; 51 | } 52 | -------------------------------------------------------------------------------- /include/dieharder/diehard_2dsphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_2dsphere test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_2dsphere(Test **test,int irun); 9 | 10 | static Dtest diehard_2dsphere_dtest __attribute__((unused)) = { 11 | "Diehard Minimum Distance (2d Circle) Test", 12 | "diehard_2dsphere", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Minimum Distance (2d Circle) Test \n\ 16 | # It does this 100 times:: choose n=8000 random points in a \n\ 17 | # square of side 10000. Find d, the minimum distance between \n\ 18 | # the (n^2-n)/2 pairs of points. If the points are truly inde- \n\ 19 | # pendent uniform, then d^2, the square of the minimum distance \n\ 20 | # should be (very close to) exponentially distributed with mean \n\ 21 | # .995 . Thus 1-exp(-d^2/.995) should be uniform on [0,1) and \n\ 22 | # a KSTEST on the resulting 100 values serves as a test of uni- \n\ 23 | # formity for random points in the square. Test numbers=0 mod 5 \n\ 24 | # are printed but the KSTEST is based on the full set of 100 \n\ 25 | # random choices of 8000 points in the 10000x10000 square. \n\ 26 | #\n\ 27 | # This test uses a fixed number of samples -- tsamples is ignored.\n\ 28 | # It also uses the default value of 100 psamples in the final\n\ 29 | # KS test, for once agreeing precisely with Diehard.\n\ 30 | #==================================================================\n", 31 | 100, 32 | 8000, 33 | 1, 34 | diehard_2dsphere, 35 | 0 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /include/dieharder/rgb_bitdist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rgb_bitdist test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int rgb_bitdist(Test **test,int irun); 9 | 10 | static Dtest rgb_bitdist_dtest __attribute__((unused)) = { 11 | "RGB Bit Distribution Test", 12 | "rgb_bitdist", 13 | "\n\ 14 | #========================================================================\n\ 15 | # RGB Bit Distribution Test\n\ 16 | # Accumulates the frequencies of all n-tuples of bits in a list\n\ 17 | # of random integers and compares the distribution thus generated\n\ 18 | # with the theoretical (binomial) histogram, forming chisq and the\n\ 19 | # associated p-value. In this test n-tuples are selected without\n\ 20 | # WITHOUT overlap (e.g. 01|10|10|01|11|00|01|10) so the samples\n\ 21 | # are independent. Every other sample is offset modulus of the\n\ 22 | # sample index and ntuple_max.\n\ 23 | #\n\ 24 | # This test must be run with -n ntuple for ntuple > 0. Note that if\n\ 25 | # ntuple > 12, one should probably increase tsamples so that each of the\n\ 26 | # 2^ntuple bins should end up with an average of around 30 occurrences.\n\ 27 | # Note also that the memory requirements and CPU time requirements will\n\ 28 | # get quite large by e.g. ntuple = 20 -- use caution when sampling the\n\ 29 | # distribution of very large ntuples.\n\ 30 | #\n", 31 | 100, /* Default psamples */ 32 | 100000, /* Default tsamples */ 33 | 1, /* We magically make all the bit tests return a single histogram */ 34 | rgb_bitdist, 35 | 0 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /include/dieharder/dab_filltree2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_filltree2 test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_filltree2(Test **test, int irun); 9 | 10 | static Dtest dab_filltree2_dtest __attribute__((unused)) = { 11 | "DAB Fill Tree 2 Test", 12 | "dab_filltree2", 13 | "\ 14 | #==========================================================\n\ 15 | # DAB Fill Tree 2 Test\n\ 16 | # Bit version of Fill Tree test.\n\ 17 | # This test fills small binary trees of fixed depth with\n\ 18 | # \"visited\" markers. When a marker cannot be placed, the\n\ 19 | # current count of markers in the tree and the position\n\ 20 | # that the marker would have been inserted, if it hadn't\n\ 21 | # already been marked.\n\ 22 | #\n\ 23 | # For each bit in the RNG input, the test takes a step\n\ 24 | # right (for a zero) or left (for a one) in the tree.\n\ 25 | # If the node hasn't been marked, it is marked, and the\n\ 26 | # path restarts. Otherwise, the test continues with the\n\ 27 | # next bit.\n\ 28 | #\n\ 29 | # The test returns two p-values. The first is a Pearson\n\ 30 | # chi-sq test against the expected values (which were\n\ 31 | # estimated empirically. The second is a Pearson chi-sq\n\ 32 | # test for a uniform distribution of the positions at\n\ 33 | # which the insert failed.\n\ 34 | #\n\ 35 | # Because of the target data for the first p-value,\n\ 36 | # ntuple must be kept at the default (128).\n\ 37 | #==========================================================\n", 38 | 1, 39 | 5000000, 40 | 2, 41 | dab_filltree2, 42 | 0 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /libdieharder/rgb_timing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $id: rgb_timing.c 142 2005-03-11 02:56:31Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | */ 6 | 7 | /* 8 | *======================================================================== 9 | * This is not a standard test -- this just times the rng. It therefore 10 | * has a very nonstandard initialization and return. One can still create 11 | * the test, but the **test struct is used only to determine the number 12 | * of samples used in the timing test. 13 | *======================================================================== 14 | */ 15 | 16 | #include 17 | 18 | int rgb_timing(Test **test, Rgb_Timing *timing) 19 | { 20 | 21 | double total_time,avg_time; 22 | int i,j; 23 | unsigned int *rand_uint; 24 | 25 | MYDEBUG(D_RGB_TIMING){ 26 | printf("# Entering rgb_timing(): ps = %u ts = %u\n",test[0]->psamples,test[0]->tsamples); 27 | } 28 | 29 | seed = random_seed(); 30 | gsl_rng_set(rng,seed); 31 | 32 | rand_uint = (uint *)malloc((size_t)test[0]->tsamples*sizeof(uint)); 33 | 34 | total_time = 0.0; 35 | for(i=0;ipsamples;i++){ 36 | start_timing(); 37 | for(j=0;jtsamples;j++){ 38 | rand_uint[j] = gsl_rng_get(rng); 39 | } 40 | stop_timing(); 41 | total_time += delta_timing(); 42 | } 43 | avg_time = total_time/(test[0]->psamples*test[0]->tsamples); 44 | 45 | timing->avg_time_nsec = avg_time*1.0e+9; 46 | timing->rands_per_sec = 1.0/avg_time; 47 | 48 | free(rand_uint); 49 | 50 | return(0); 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /libdieharder/Xtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: Xtest.c 239 2006-10-03 18:56:47Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | /* 10 | *======================================================================== 11 | * This should be a nice, big case switch where we add EACH test 12 | * we might want to do and either just configure and do it or 13 | * prompt for input (if absolutely necessary) and then do it. 14 | *======================================================================== 15 | */ 16 | 17 | #include 18 | 19 | void Xtest_eval(Xtest *xtest) 20 | { 21 | 22 | /* 23 | * This routine evaluates the p-value from the xtest data. 24 | * x, y, sigma all must be filled in by the calling routine. 25 | */ 26 | /* 27 | xtest->pvalue = 28 | 0.5*gsl_sf_erfc((xtest->y - xtest->x)/(sqrt(2.0)*xtest->sigma)); 29 | xtest->pvalue = 30 | 1 - 0.5*gsl_sf_erfc((xtest->y - xtest->x)/(sqrt(2.0)*xtest->sigma)); 31 | xtest->pvalue = 32 | gsl_sf_erfc(fabs(xtest->y - xtest->x)/(sqrt(2.0)*xtest->sigma)); 33 | */ 34 | xtest->pvalue = 35 | gsl_cdf_gaussian_P(xtest->y - xtest->x,xtest->sigma); 36 | 37 | if(verbose == D_XTEST || verbose == D_ALL){ 38 | printf("# Xtest_eval(): x = %10.5f y = %10.5f sigma = %10.5f\n", 39 | xtest->x, xtest->y, xtest->sigma); 40 | printf("# Xtest_eval(): p-value = %10.5f\n",xtest->pvalue); 41 | } 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /manual/dieharder.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [0][-]{chapter.1}{Introduction}{} 2 | \BOOKMARK [0][-]{chapter.2}{Testing Random Number Generators}{} 3 | \BOOKMARK [0][-]{chapter.3}{Evaluating p-values}{} 4 | \BOOKMARK [1][-]{section.3.1}{Xtest -- A Single Expected Value}{chapter.3} 5 | \BOOKMARK [1][-]{section.3.2}{Vtest -- A Vector of Expected Values}{chapter.3} 6 | \BOOKMARK [2][-]{subsection.3.2.1}{Kolmogorov-Smirnov Test}{section.3.2} 7 | \BOOKMARK [1][-]{section.3.3}{The Test Histogram}{chapter.3} 8 | \BOOKMARK [0][-]{chapter.4}{Diehard}{} 9 | \BOOKMARK [1][-]{section.4.1}{The Original Diehard}{chapter.4} 10 | \BOOKMARK [1][-]{section.4.2}{The Dieharder Modifications}{chapter.4} 11 | \BOOKMARK [0][-]{chapter.5}{Dieharder's Modular Test Structure}{} 12 | \BOOKMARK [0][-]{chapter.6}{Dieharder Extensions}{} 13 | \BOOKMARK [1][-]{section.6.1}{STS Tests}{chapter.6} 14 | \BOOKMARK [1][-]{section.6.2}{New Tests}{chapter.6} 15 | \BOOKMARK [1][-]{section.6.3}{Future \(Proposed or Planned\) Tests}{chapter.6} 16 | \BOOKMARK [0][-]{chapter.7}{Results for Selected Generators}{} 17 | \BOOKMARK [1][-]{subsection.7.0.1}{A Good Generator: mt19937\1371999}{chapter.7} 18 | \BOOKMARK [2][-]{subsection.7.0.2}{Comments}{subsection.7.0.1} 19 | \BOOKMARK [1][-]{section.7.1}{A Bad Generator: randu}{chapter.7} 20 | \BOOKMARK [1][-]{section.7.2}{An Ugly Generator: slatec}{chapter.7} 21 | \BOOKMARK [0][-]{chapter.8}{Conclusions}{} 22 | \BOOKMARK [0][-]{appendix.A}{License Terms}{} 23 | \BOOKMARK [1][-]{section.A.1}{General Terms}{appendix.A} 24 | \BOOKMARK [1][-]{section.A.2}{OPEN PUBLICATION LICENSE Draft v0.4, 8 June 1999}{appendix.A} 25 | -------------------------------------------------------------------------------- /include/dieharder/diehard_runs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_runs test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_runs(Test **test,int irun); 9 | 10 | static Dtest diehard_runs_dtest __attribute__((unused)) = { 11 | "Diehard Runs Test", 12 | "diehard_runs", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Runs Test\n\ 16 | # This is the RUNS test. It counts runs up, and runs down, \n\ 17 | # in a sequence of uniform [0,1) variables, obtained by float- \n\ 18 | # ing the 32-bit integers in the specified file. This example \n\ 19 | # shows how runs are counted: .123,.357,.789,.425,.224,.416,.95\n\ 20 | # contains an up-run of length 3, a down-run of length 2 and an \n\ 21 | # up-run of (at least) 2, depending on the next values. The \n\ 22 | # covariance matrices for the runs-up and runs-down are well \n\ 23 | # known, leading to chisquare tests for quadratic forms in the \n\ 24 | # weak inverses of the covariance matrices. Runs are counted \n\ 25 | # for sequences of length 10,000. This is done ten times. Then \n\ 26 | # repeated. \n\ 27 | #\n\ 28 | # In Dieharder sequences of length tsamples = 100000 are used by\n\ 29 | # default, and 100 p-values thus generated are used in a final\n\ 30 | # KS test.\n\ 31 | #==================================================================\n", 32 | 100, /* Default psamples */ 33 | 100000, /* Default tsamples */ 34 | 2, /* runs returns two pvalues, not just one */ 35 | diehard_runs, 36 | 0 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /include/dieharder/verbose.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: libdieharder.h 220 2006-08-16 19:26:56Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | 10 | #define MYDEBUG(b) if ( (verbose == b) || (verbose == D_ALL) ) 11 | 12 | typedef enum { 13 | D_QUIET, 14 | D_ALL, 15 | D_DIEHARD_BDAY, 16 | D_DIEHARD_OPERM5, 17 | D_DIEHARD_RANK_32x32, 18 | D_DIEHARD_RANK_6x8, 19 | D_DIEHARD_BITSTREAM, 20 | D_DIEHARD_OPSO, 21 | D_DIEHARD_OQSO, 22 | D_DIEHARD_DNA, 23 | D_DIEHARD_COUNT_1S_STREAM, 24 | D_DIEHARD_COUNT_1S_BYTE, 25 | D_DIEHARD_PARKING_LOT, 26 | D_DIEHARD_2DSPHERE, 27 | D_DIEHARD_3DSPHERE, 28 | D_DIEHARD_SQUEEZE, 29 | D_DIEHARD_SUMS, 30 | D_DIEHARD_RUNS, 31 | D_DIEHARD_CRAPS, 32 | D_MARSAGLIA_TSANG_GCD, 33 | D_MARSAGLIA_TSANG_GORILLA, 34 | D_RGB_TIMING, 35 | D_RGB_PERSIST, 36 | D_RGB_BITDIST, 37 | D_RGB_KSTEST_TEST, 38 | D_RGB_MINIMUM_DISTANCE, 39 | D_RGB_PERMUTATIONS, 40 | D_RGB_LAGGED_SUMS, 41 | D_RGB_LMN, 42 | D_RGB_OPERM, 43 | D_STS_MONOBIT, 44 | D_STS_RUNS, 45 | D_STS_SERIAL, 46 | D_STS_BLOCK, 47 | D_TYPES, 48 | D_USER_TEMPLATE, 49 | D_MEASURE, 50 | D_SEED, 51 | D_STARTUP, 52 | D_BITS, 53 | D_SAMPLE, 54 | D_CHISQ, 55 | D_KSTEST, 56 | D_VTEST, 57 | D_XTEST, 58 | D_BRANK, 59 | D_FILE_INPUT, 60 | D_FILE_INPUT_RAW, 61 | D_ADD_MY_TYPES, 62 | D_STD_TEST, 63 | D_RNGS, 64 | N_DEBUG 65 | } Debug; 66 | -------------------------------------------------------------------------------- /include/dieharder/rgb_kstest_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rgb_kstest_test test header 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int rgb_kstest_test(Test **test,int irun); 9 | 10 | static Dtest rgb_kstest_test_dtest __attribute__((unused)) = { 11 | "RGB Kolmogorov-Smirnov Test Test", 12 | "rgb_kstest_test", 13 | "#\n\ 14 | # The Kolmogorov-Smirnov Test Test\n\ 15 | #\n\ 16 | #\n\ 17 | # This test generates a vector of tsamples uniform deviates from the\n\ 18 | # selected rng, then applies an Anderson-Darling or Kuiper KS test to\n\ 19 | # it to directly test for uniformity. The AD version has been symmetrized\n\ 20 | # to correct for weak left bias for small sample sets; Kuiper is already\n\ 21 | # ring-symmetric on the interval. The AD code corresponds roughly to\n\ 22 | # what is in R (thanks to a correction sent in by David Bauer).\n\ 23 | # As always, the test is run pvalues times and the (same) KS test is then\n\ 24 | # used to generate a final test pvalue, but the real purpose of this test\n\ 25 | # is to test ADKS and KKS, not to test rngs. This test clearly reveals\n\ 26 | # that kstests run on only 100 test values (tsamples, herein) are only\n\ 27 | # approximately accurate; their pvalues are distinctly high-biased (but\n\ 28 | # less so than Kuiper or KS before the fix). This bias is hardly visible\n\ 29 | # for less than 1000 trivals (psamples, herein) but will constently cause\n\ 30 | # failure for -t 100, -p 10000 or higher. For -t 1000, it is much more\n\ 31 | # difficult to detect, and the final kstest is approximately valid for the\n\ 32 | # test in question.\n\ 33 | #\n", 34 | 1000, 35 | 10000, 36 | 1, 37 | rgb_kstest_test, 38 | 0 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /libdieharder/rng_dev_random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_random 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * 6 | */ 7 | 8 | #include 9 | 10 | static unsigned long int dev_random_get (void *vstate); 11 | static double dev_random_get_double (void *vstate); 12 | static void dev_random_set (void *vstate, unsigned long int s); 13 | 14 | typedef struct 15 | { 16 | FILE *fp; 17 | } 18 | dev_random_state_t; 19 | 20 | static unsigned long int 21 | dev_random_get (void *vstate) 22 | { 23 | dev_random_state_t *state = (dev_random_state_t *) vstate; 24 | unsigned long int j; 25 | 26 | if(state->fp != NULL) { 27 | fread(&j,sizeof(j),1,state->fp); 28 | return j; 29 | } else { 30 | fprintf(stderr,"Error: /dev/random not open. Exiting.\n"); 31 | exit(0); 32 | } 33 | 34 | } 35 | 36 | static double 37 | dev_random_get_double (void *vstate) 38 | { 39 | return dev_random_get (vstate) / (double) UINT_MAX; 40 | } 41 | 42 | static void 43 | dev_random_set (void *vstate, unsigned long int s) 44 | { 45 | dev_random_state_t *state = (dev_random_state_t *) vstate; 46 | 47 | if ((state->fp = fopen("/dev/random","r")) == NULL) { 48 | fprintf(stderr,"Error: Cannot open /dev/random, exiting.\n"); 49 | fprintf(stderr,"/dev/random may only be available on Linux systems.\n"); 50 | exit(0); 51 | } 52 | 53 | return; 54 | 55 | } 56 | 57 | static const gsl_rng_type dev_random_type = 58 | {"/dev/random", /* name */ 59 | UINT_MAX, /* RAND_MAX */ 60 | 0, /* RAND_MIN */ 61 | sizeof (dev_random_state_t), 62 | &dev_random_set, 63 | &dev_random_get, 64 | &dev_random_get_double}; 65 | 66 | const gsl_rng_type *gsl_rng_dev_random = &dev_random_type; 67 | -------------------------------------------------------------------------------- /libdieharder/rng_dev_urandom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_urandom 3 | */ 4 | 5 | #include 6 | 7 | /* 8 | * This is a wrapping of the /dev/random hardware rng 9 | */ 10 | static unsigned long int dev_urandom_get (void *vstate); 11 | static double dev_urandom_get_double (void *vstate); 12 | static void dev_urandom_set (void *vstate, unsigned long int s); 13 | 14 | typedef struct 15 | { 16 | FILE *fp; 17 | } 18 | dev_urandom_state_t; 19 | 20 | static unsigned long int 21 | dev_urandom_get (void *vstate) 22 | { 23 | dev_urandom_state_t *state = (dev_urandom_state_t *) vstate; 24 | unsigned long int j; 25 | 26 | if(state->fp != NULL) { 27 | fread(&j,sizeof(j),1,state->fp); 28 | return j; 29 | } else { 30 | fprintf(stderr,"Error: /dev/urandom not open. Exiting.\n"); 31 | exit(0); 32 | } 33 | 34 | } 35 | 36 | static double 37 | dev_urandom_get_double (void *vstate) 38 | { 39 | return dev_urandom_get (vstate) / (double) UINT_MAX; 40 | } 41 | 42 | static void 43 | dev_urandom_set (void *vstate, unsigned long int s) 44 | { 45 | dev_urandom_state_t *state = (dev_urandom_state_t *) vstate; 46 | 47 | if ((state->fp = fopen("/dev/urandom","r")) == NULL) { 48 | fprintf(stderr,"Error: Cannot open /dev/urandom, exiting.\n"); 49 | fprintf(stderr,"/dev/urandom may only be available on Linux systems.\n"); 50 | exit(0); 51 | } 52 | 53 | return; 54 | 55 | } 56 | 57 | static const gsl_rng_type dev_urandom_type = 58 | {"/dev/urandom", /* name */ 59 | UINT_MAX, /* RAND_MAX */ 60 | 0, /* RAND_MIN */ 61 | sizeof (dev_urandom_state_t), 62 | &dev_urandom_set, 63 | &dev_urandom_get, 64 | &dev_urandom_get_double}; 65 | 66 | const gsl_rng_type *gsl_rng_dev_urandom = &dev_urandom_type; 67 | -------------------------------------------------------------------------------- /include/dieharder/diehard_count_1s_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_count_1s_stream test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_count_1s_stream(Test **test,int irun); 9 | 10 | static Dtest diehard_count_1s_stream_dtest __attribute__((unused)) = { 11 | "Diehard Count the 1s (stream) Test", 12 | "diehard_count_1s_stream", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Count the 1s (stream) (modified) Test.\n\ 16 | # Consider the file under test as a stream of bytes (four per \n\ 17 | # 32 bit integer). Each byte can contain from 0 to 8 1's, \n\ 18 | # with probabilities 1,8,28,56,70,56,28,8,1 over 256. Now let \n\ 19 | # the stream of bytes provide a string of overlapping 5-letter \n\ 20 | # words, each \"letter\" taking values A,B,C,D,E. The letters are \n\ 21 | # determined by the number of 1's in a byte:: 0,1,or 2 yield A,\n\ 22 | # 3 yields B, 4 yields C, 5 yields D and 6,7 or 8 yield E. Thus \n\ 23 | # we have a monkey at a typewriter hitting five keys with vari- \n\ 24 | # ous probabilities (37,56,70,56,37 over 256). There are 5^5 \n\ 25 | # possible 5-letter words, and from a string of 256,000 (over- \n\ 26 | # lapping) 5-letter words, counts are made on the frequencies \n\ 27 | # for each word. The quadratic form in the weak inverse of \n\ 28 | # the covariance matrix of the cell counts provides a chisquare \n\ 29 | # test:: Q5-Q4, the difference of the naive Pearson sums of \n\ 30 | # (OBS-EXP)^2/EXP on counts for 5- and 4-letter cell counts. \n\ 31 | #==================================================================\n", 32 | 100, 33 | 256000, 34 | 1, 35 | diehard_count_1s_stream, 36 | 0 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /libdieharder/rng_dev_arandom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_arandom 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * 6 | */ 7 | 8 | #include 9 | 10 | static unsigned long int dev_arandom_get (void *vstate); 11 | static double dev_arandom_get_double (void *vstate); 12 | static void dev_arandom_set (void *vstate, unsigned long int s); 13 | 14 | typedef struct 15 | { 16 | FILE *fp; 17 | } 18 | dev_arandom_state_t; 19 | 20 | static unsigned long int 21 | dev_arandom_get (void *vstate) 22 | { 23 | dev_arandom_state_t *state = (dev_arandom_state_t *) vstate; 24 | unsigned long int j; 25 | 26 | if(state->fp != NULL) { 27 | fread(&j,sizeof(j),1,state->fp); 28 | return j; 29 | } else { 30 | fprintf(stderr,"Error: /dev/arandom not open. Exiting.\n"); 31 | exit(0); 32 | } 33 | 34 | } 35 | 36 | static double 37 | dev_arandom_get_double (void *vstate) 38 | { 39 | return dev_arandom_get (vstate) / (double) UINT_MAX; 40 | } 41 | 42 | static void 43 | dev_arandom_set (void *vstate, unsigned long int s) 44 | { 45 | dev_arandom_state_t *state = (dev_arandom_state_t *) vstate; 46 | 47 | if ((state->fp = fopen("/dev/arandom","r")) == NULL) { 48 | fprintf(stderr,"Error: Cannot open /dev/arandom, exiting.\n"); 49 | fprintf(stderr,"/dev/arandom may only be available on BSD systems.\n"); 50 | exit(0); 51 | } 52 | 53 | return; 54 | 55 | } 56 | 57 | static const gsl_rng_type dev_arandom_type = 58 | {"/dev/arandom", /* name */ 59 | UINT_MAX, /* RAND_MAX */ 60 | 0, /* RAND_MIN */ 61 | sizeof (dev_arandom_state_t), 62 | &dev_arandom_set, 63 | &dev_arandom_get, 64 | &dev_arandom_get_double}; 65 | 66 | const gsl_rng_type *gsl_rng_dev_arandom = &dev_arandom_type; 67 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | nobase_include_HEADERS = dieharder/copyright.h \ 2 | dieharder/dab_bytedistrib.h \ 3 | dieharder/dab_dct.h \ 4 | dieharder/dab_filltree2.h \ 5 | dieharder/dab_filltree.h \ 6 | dieharder/dab_monobit2.h \ 7 | dieharder/dieharder_rng_types.h \ 8 | dieharder/dieharder_test_types.h \ 9 | dieharder/diehard_2dsphere.h \ 10 | dieharder/diehard_3dsphere.h \ 11 | dieharder/diehard_birthdays.h \ 12 | dieharder/diehard_bitstream.h \ 13 | dieharder/diehard_count_1s_byte.h \ 14 | dieharder/diehard_count_1s_stream.h \ 15 | dieharder/diehard_craps.h \ 16 | dieharder/diehard_dna.h \ 17 | dieharder/diehard_operm5.h \ 18 | dieharder/diehard_opso.h \ 19 | dieharder/diehard_oqso.h \ 20 | dieharder/diehard_parking_lot.h \ 21 | dieharder/diehard_rank_32x32.h \ 22 | dieharder/diehard_rank_6x8.h \ 23 | dieharder/diehard_runs.h \ 24 | dieharder/diehard_squeeze.h \ 25 | dieharder/diehard_sums.h \ 26 | dieharder/Dtest.h \ 27 | dieharder/libdieharder.h \ 28 | dieharder/marsaglia_tsang_gcd.h \ 29 | dieharder/marsaglia_tsang_gorilla.h \ 30 | dieharder/parse.h \ 31 | dieharder/rgb_bitdist.h \ 32 | dieharder/rgb_kstest_test.h \ 33 | dieharder/rgb_lagged_sums.h \ 34 | dieharder/rgb_lmn.h \ 35 | dieharder/rgb_minimum_distance.h \ 36 | #dieharder/rgb_operm.h \ 37 | dieharder/rgb_persist.h \ 38 | dieharder/rgb_permutations.h \ 39 | dieharder/rgb_timing.h \ 40 | dieharder/std_test.h \ 41 | dieharder/sts_monobit.h \ 42 | dieharder/sts_runs.h \ 43 | dieharder/sts_serial.h \ 44 | dieharder/tests.h \ 45 | dieharder/verbose.h \ 46 | dieharder/Vtest.h \ 47 | dieharder/Xtest.h \ 48 | dieharder/dab_bytedistrib.h \ 49 | dieharder/dab_dct.h \ 50 | dieharder/dab_filltree2.h \ 51 | dieharder/dab_filltree.h \ 52 | dieharder/dab_monobit2.h 53 | -------------------------------------------------------------------------------- /include/dieharder/diehard_sums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_sums test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_sums(Test **test,int irun); 9 | 10 | static Dtest diehard_sums_dtest __attribute__((unused)) = { 11 | "Diehard Sums Test", 12 | "diehard_sums", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Sums Test\n\ 16 | # Integers are floated to get a sequence U(1),U(2),... of uni- \n\ 17 | # form [0,1) variables. Then overlapping sums, \n\ 18 | # S(1)=U(1)+...+U(100), S2=U(2)+...+U(101),... are formed. \n\ 19 | # The S's are virtually normal with a certain covariance mat- \n\ 20 | # rix. A linear transformation of the S's converts them to a \n\ 21 | # sequence of independent standard normals, which are converted \n\ 22 | # to uniform variables for a KSTEST. The p-values from ten \n\ 23 | # KSTESTs are given still another KSTEST. \n\ 24 | #\n\ 25 | # Comments\n\ 26 | #\n\ 27 | # At this point I think there is rock solid evidence that this test\n\ 28 | # is completely useless in every sense of the word. It is broken,\n\ 29 | # and it is so broken that there is no point in trying to fix it.\n\ 30 | # The problem is that the transformation above is not linear, and\n\ 31 | # doesn't work. Don't use it.\n\ 32 | #\n\ 33 | # For what it is worth, rgb_lagged_sums with ntuple 0 tests for\n\ 34 | # exactly the same thing, but scalably and reliably without the\n\ 35 | # complication of overlapping samples and covariance. Use it\n\ 36 | # instead.\n\ 37 | #==================================================================\n", 38 | 100, 39 | 100, 40 | 1, 41 | diehard_sums, 42 | 0 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /include/dieharder/std_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is is the std_test struct. It is the sole output interface between 3 | * the user and the test program -- all standard test inputs and returns 4 | * are passed through this struct. A test can have additional user-settable 5 | * arguments, of course, but they must be passed in GLOBAL SHARED VARIABLES 6 | * defined just for the particular test in question. This is a bit ugly, 7 | * but so are void *args argument lists and va_start/va_end for multiple 8 | * layers of passing arguments. 9 | * 10 | * This is silly. We clearly need for each test to have access to all 11 | * variables set on the command line. That way the ONE Test object 12 | * can be passed to e.g report() or table() and they'll know exactly 13 | * what to do with it. 14 | */ 15 | typedef struct { 16 | unsigned int nkps; /* Number of test statistics created per run */ 17 | unsigned int tsamples; /* Number of samples per test (if applicable) */ 18 | unsigned int psamples; /* Number of test runs per final KS p-value */ 19 | unsigned int ntuple; /* Number of bits in ntuples being tested */ 20 | double *pvalues; /* Vector of length psamples to hold test p-values */ 21 | char *pvlabel; /* Vector of length LINE to hold labels per p-value */ 22 | double ks_pvalue; /* Final KS p-value from run of many tests */ 23 | double x; /* Extra variable passed on command line */ 24 | double y; /* Extra variable passed on command line */ 25 | double z; /* Extra variable passed on command line */ 26 | } Test; 27 | 28 | 29 | Test **create_test(Dtest *dtest, unsigned int tsamples, unsigned int psamples); 30 | void destroy_test(Dtest *dtest, Test **test); 31 | void std_test(Dtest *dtest, Test **test); 32 | 33 | -------------------------------------------------------------------------------- /include/dieharder/rgb_persist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_rgb_persist test header. This test needs to just go 3 | * away... 4 | */ 5 | 6 | /* 7 | * function prototype 8 | */ 9 | typedef struct { 10 | unsigned int nbits; 11 | unsigned int and_mask; 12 | unsigned int cumulative_mask; 13 | } Rgb_Persist; 14 | int rgb_persist(Test **test, Rgb_Persist *persist); 15 | 16 | static Dtest rgb_persist_dtest __attribute__((unused)) = { 17 | "RGB Bit Persistence Test", 18 | "rgb_persist", 19 | "\n\ 20 | #========================================================================\n\ 21 | # RGB Bit Persistence Test\n\ 22 | # This test generates 256 sequential samples of an random unsigned\n\ 23 | # integer from the given rng. Successive integers are logically\n\ 24 | # processed to extract a mask with 1's whereever bits do not\n\ 25 | # change. Since bits will NOT change when filling e.g. unsigned\n\ 26 | # ints with 16 bit ints, this mask logically &'d with the maximum\n\ 27 | # random number returned by the rng. All the remaining 1's in the\n\ 28 | # resulting mask are therefore significant -- they represent bits\n\ 29 | # that never change over the length of the test. These bits are\n\ 30 | # very likely the reason that certain rng's fail the monobit\n\ 31 | # test -- extra persistent e.g. 1's or 0's inevitably bias the\n\ 32 | # total bitcount. In many cases the particular bits repeated\n\ 33 | # appear to depend on the seed. If the -i flag is given, the\n\ 34 | # entire test is repeated with the rng reseeded to generate a mask\n\ 35 | # and the extracted mask cumulated to show all the possible bit\n\ 36 | # positions that might be repeated for different seeds.\n\ 37 | ", 38 | 1, 39 | 256, 40 | 1, 41 | rgb_persist, 42 | 0 43 | }; 44 | 45 | extern unsigned int *rgb_persist_rand_uint; 46 | -------------------------------------------------------------------------------- /include/dieharder/diehard_birthdays.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_birthdays test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_birthdays(Test **test, int irun); 9 | 10 | static Dtest diehard_birthdays_dtest __attribute__((unused)) = { 11 | "Diehard Birthdays Test", 12 | "diehard_birthdays", 13 | "\n\ 14 | #==================================================================\n\ 15 | # Diehard \"Birthdays\" test (modified).\n\ 16 | # Each test determines the number of matching intervals from 512\n\ 17 | # \"birthdays\" (by default) drawn on a 24-bit \"year\" (by\n\ 18 | # default). This is repeated 100 times (by default) and the\n\ 19 | # results cumulated in a histogram. Repeated intervals should be\n\ 20 | # distributed in a Poisson distribution if the underlying generator\n\ 21 | # is random enough, and a a chisq and p-value for the test are\n\ 22 | # evaluated relative to this null hypothesis.\n\ 23 | #\n\ 24 | # It is recommended that you run this at or near the original\n\ 25 | # 100 test samples per p-value with -t 100.\n\ 26 | #\n\ 27 | # Two additional parameters have been added. In diehard, nms=512\n\ 28 | # but this CAN be varied and all Marsaglia's formulae still work. It\n\ 29 | # can be reset to different values with -x nmsvalue.\n\ 30 | # Similarly, nbits \"should\" 24, but we can really make it anything\n\ 31 | # we want that's less than or equal to rmax_bits = 32. It can be\n\ 32 | # reset to a new value with -y nbits. Both default to diehard's\n\ 33 | # values if no -x or -y options are used.\n\ 34 | #==================================================================\n", 35 | 100, 36 | 100, 37 | 1, 38 | diehard_birthdays, 39 | 0 40 | }; 41 | 42 | /* 43 | * Global variables 44 | uint diehard_birthdays_nms,diehard_birthdays_nbits; 45 | uint *diehard_birthdays_rand_uint; 46 | */ 47 | -------------------------------------------------------------------------------- /libdieharder/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: list_rngs.c 420 2008-08-18 18:29:17Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | */ 6 | 7 | /* 8 | * ======================================================================== 9 | * These two functions JUST output a "standard header" with version and 10 | * copyright information for use in various output routines or the version 11 | * information alone. Note that version might be e.g. 3.28.0beta, that 12 | * is, it may not be strictly numerical. 13 | * ======================================================================== 14 | */ 15 | 16 | #include "dieharder/libdieharder.h" 17 | 18 | /* 19 | * dh_header isn't QUITE trivial, because the version string can vary in 20 | * length. If it is longer than around 20 characters, this is going to 21 | * make ugly output but nothing should "break". Note that we assume 80 22 | * character lines, sorry. 23 | */ 24 | 25 | #define LINE_LENGTH 80 26 | void dh_header() 27 | { 28 | 29 | int i,half,version_length; 30 | 31 | version_length = strlen(QUOTEME(VERSION)); 32 | 33 | fprintf(stdout,"#=============================================================================#\n"); 34 | fprintf(stdout,"#"); 35 | /* Pad the front */ 36 | half = (LINE_LENGTH - 48 - version_length - 2)/2; 37 | for(i=0;i 14 | 15 | void marsaglia_tsang_gorilla(Test **test, int irun) 16 | { 17 | 18 | uint t,i,lag; 19 | Xtest ptest; 20 | 21 | /* 22 | * ptest.x = actual sum of test[0]->tsamples lagged samples from rng 23 | * ptest.y = test[0]->tsamples*0.5 is the expected mean value of the sum 24 | * ptest.sigma = sqrt(test[0]->tsamples/12.0) is the standard deviation 25 | */ 26 | ptest.x = 0.0; /* Initial value */ 27 | ptest.y = (double) test[0]->tsamples*0.5; 28 | ptest.sigma = sqrt(test[0]->tsamples/12.0); 29 | 30 | /* 31 | * sample only every lag returns from the rng, discard the rest. 32 | * We have to get the (float) value from the user input and set 33 | * a uint 34 | */ 35 | if(x_user){ 36 | lag = x_user; 37 | } else { 38 | lag = 2; /* Why not? Anything but 0, really... */ 39 | } 40 | 41 | if(verbose == D_USER_TEMPLATE || verbose == D_ALL){ 42 | printf("# marsaglia_tsang_gorilla(): Doing a test on lag %u\n",lag); 43 | } 44 | 45 | for(t=0;ttsamples;t++){ 46 | 47 | /* 48 | * A VERY SIMPLE test (probably not too sensitive) 49 | */ 50 | 51 | /* Throw away lag-1 per sample */ 52 | for(i=0;i<(lag-1);i++) gsl_rng_uniform(rng); 53 | 54 | /* sample only every lag numbers, reset counter */ 55 | ptest.x += gsl_rng_uniform(rng); 56 | 57 | } 58 | 59 | Xtest_eval(&ptest); 60 | test[0]->pvalues[irun] = ptest.pvalue; 61 | 62 | MYDEBUG(D_MARSAGLIA_TSANG_GORILLA) { 63 | printf("# marsaglia_tsang_gorilla(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /dieharder/add_ui_rngs.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * See copyright in copyright.h and the accompanying file COPYING 4 | *======================================================================== 5 | */ 6 | 7 | #include "dieharder.h" 8 | 9 | /* 10 | * ======================================================================== 11 | * This adds JUST the one example generator included with the dieharder 12 | * sources. It is provided only to give people a template to follow to 13 | * add their own rng inside a GSL/dieharder-compatible testing harness. 14 | * ======================================================================== 15 | */ 16 | 17 | void add_ui_rngs() 18 | { 19 | /* 20 | * If you are hacking dieharder to add your own rng, add it below using 21 | * the "empty_random" example as a template (right AFTER the example) and 22 | * it should "just appear" in the dieharder list of available generators 23 | * and be immediately useful. Note that the range 600-699 is currently 24 | * reserved "only" for UI rngs. 25 | int i = 600; 26 | */ 27 | dh_num_user_rngs = 0; 28 | /* Template from here. Uncomment and fill in your own generator: 29 | dh_rng_types[i] = gsl_rng_empty_random; 30 | i++; 31 | */ 32 | dh_num_user_rngs++; 33 | dh_num_rngs++; 34 | /* to here.*/ 35 | MYDEBUG(D_STARTUP){ 36 | printf("# startup: Found %u user interface generators.\n",dh_num_user_rngs); 37 | printf("# startup: A total of %u generators available.\n",dh_num_rngs); 38 | } 39 | 40 | /* 41 | * If you are writing an entirely new UI, e.g. to add dieharder 42 | * functionality to things such as octave or a new GUI, yes, there is 43 | * a reserved range for you as well -- 700-999 is for custom UI rngs that 44 | * don't fit into any of the categories above. Just block copy the 45 | * enter user example and set i = 700 to start and increment the 46 | * global dh_num_reserved_rngs counter. 47 | */ 48 | } 49 | 50 | -------------------------------------------------------------------------------- /libdieharder/random_seed.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: random_seed.c 223 2006-08-17 06:19:38Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | /* 10 | *======================================================================== 11 | * This routine does all the required initialization and startup, 12 | * including memory allocation and prefilling of vectors. It is 13 | * COMPLETELY outside the timing loops. 14 | *======================================================================== 15 | */ 16 | 17 | #include 18 | 19 | unsigned long int random_seed() 20 | { 21 | 22 | unsigned int seed; 23 | struct timeval tv; 24 | FILE *devurandom; 25 | 26 | /* 27 | * We will routinely use /dev/urandom here, which is entropic noise 28 | * supplemented by an RNG of high quality. This is much faster than 29 | * /dev/random (doesn't block when the entropy pool is exhausted) and 30 | * should serve our purpose of providing a sufficiently random and 31 | * uniformly distributed seed. 32 | * 33 | * It falls back on the clock, which is a POOR choice. I really should 34 | * use the clock to seed a good rng (e.g. mt19937), generate a 35 | * random integer in the range 1-100, discard this number of rand and use 36 | * the next one as the seed (for example). The point isn't to get a 37 | * perfectly random seed -- it is to get a uniform distribution of possible 38 | * seeds. 39 | */ 40 | if ((devurandom = fopen("/dev/urandom","r")) == NULL) { 41 | gettimeofday(&tv,0); 42 | seed = tv.tv_sec + tv.tv_usec; 43 | if(verbose == D_SEED) printf("Got seed %u from gettimeofday()\n",seed); 44 | } else { 45 | fread(&seed,sizeof(seed),1,devurandom); 46 | if(verbose == D_SEED) printf("Got seed %u from /dev/urandom\n",seed); 47 | fclose(devurandom); 48 | } 49 | 50 | return(seed); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/dieharder/diehard_bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_bitstream test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_bitstream(Test **test,int irun); 9 | 10 | static Dtest diehard_bitstream_dtest __attribute__((unused)) = { 11 | "Diehard Bitstream Test", 12 | "diehard_bitstream", 13 | "\n\ 14 | #==================================================================\n\ 15 | # Diehard Bitstream Test.\n\ 16 | # The file under test is viewed as a stream of bits. Call them \n\ 17 | # b1,b2,... . Consider an alphabet with two \"letters\", 0 and 1 \n\ 18 | # and think of the stream of bits as a succession of 20-letter \n\ 19 | # \"words\", overlapping. Thus the first word is b1b2...b20, the \n\ 20 | # second is b2b3...b21, and so on. The bitstream test counts \n\ 21 | # the number of missing 20-letter (20-bit) words in a string of \n\ 22 | # 2^21 overlapping 20-letter words. There are 2^20 possible 20 \n\ 23 | # letter words. For a truly random string of 2^21+19 bits, the \n\ 24 | # number of missing words j should be (very close to) normally \n\ 25 | # distributed with mean 141,909 and sigma 428. Thus \n\ 26 | # (j-141909)/428 should be a standard normal variate (z score) \n\ 27 | # that leads to a uniform [0,1) p value. The test is repeated \n\ 28 | # twenty times. \n\ 29 | #\n\ 30 | # NOTE WELL!\n\ 31 | #\n\ 32 | # The test is repeated 100 times by default in dieharder, but the\n\ 33 | # size of the sample is fixed (tsamples cannot/should not be\n\ 34 | # varied from the default). The sigma of this test REQUIRES the\n\ 35 | # use of overlapping samples, and overlapping samples are not\n\ 36 | # independent. If one uses the non-overlapping version of this\n\ 37 | # test, sigma = 290 is used instead, smaller because now there\n\ 38 | # are 2^21 INDEPENDENT samples.\n\ 39 | #==================================================================\n", 40 | 100, 41 | 2097152, 42 | 1, 43 | diehard_bitstream, 44 | 0 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /dieharder/add_ui_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * See copyright in copyright.h and the accompanying file COPYING 4 | *======================================================================== 5 | */ 6 | 7 | #include "dieharder.h" 8 | 9 | /* 10 | * ======================================================================== 11 | * This adds JUST the one example test included with the dieharder 12 | * sources. It is provided only to give people a template to follow to 13 | * add their own test(s) to dieharder. Note well, however, that this is 14 | * not a trivial process. 15 | * ======================================================================== 16 | */ 17 | 18 | void add_ui_tests() 19 | { 20 | 21 | int i; 22 | 23 | /* 24 | * If you are hacking dieharder to add your own test, add it below using 25 | * the "empty_random" example as a template (right AFTER the example) and 26 | * it should "just appear" in the dieharder list of available generators 27 | * and be immediately useful. Note that the range 600-699 is currently 28 | * reserved "only" for UI rngs. 29 | */ 30 | i = 600; 31 | dh_num_user_tests = 0; 32 | ADD_TEST(&user_template_dtest); 33 | dh_num_user_tests++; 34 | 35 | /* 36 | * Please do not exceed the i=600-899 range. 900 and higher are reserved 37 | * for test development at this time and are not looped over in 38 | * run_all_tests(). 39 | */ 40 | 41 | /* 42 | * This is the total number of DOCUMENTED tests reported back to the UIs. 43 | * Note that dh_num_[diehard,sts,other]_tests are counted up by 44 | * dieharder_test_types(), which also sets this variable (so they can be 45 | * called in either order). 46 | */ 47 | dh_num_tests = dh_num_diehard_tests + dh_num_sts_tests + dh_num_other_tests 48 | + dh_num_user_tests; 49 | 50 | MYDEBUG(D_STARTUP){ 51 | printf("# startup: Found %u user interface generators.\n",dh_num_user_tests); 52 | printf("# startup: A total of %u generators available.\n",dh_num_tests); 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /include/dieharder/dab_dct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_dct test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_dct(Test **test, int irun); 9 | 10 | static Dtest dab_dct_dtest __attribute__((unused)) = { 11 | "DAB DCT", 12 | "dab_dct", 13 | "\ 14 | #========================================================================\n\ 15 | # DCT (Frequency Analysis) Test\n\ 16 | #========================================================================\n\ 17 | #\n\ 18 | # This test performs a Discrete Cosine Transform (DCT) on the output of\n\ 19 | # the RNG. More specifically, it performs tsamples transforms, each over\n\ 20 | # an independent block of ntuple words. If tsamples is large enough, the\n\ 21 | # positions of the maximum (absolute) value in each transform are\n\ 22 | # recorded and subjected to a chisq test for uniformity/independence. [1]\n\ 23 | # (A standard type II DCT is used.)\n\ 24 | # \n\ 25 | # If tsamples is smaller than or equal to 5 times ntuple then a fallback\n\ 26 | # test will be used, whereby all DCT values are converted to p-values\n\ 27 | # and tested for uniformity via a KS test. This version is significantly\n\ 28 | # less sensitive, and is not recommended.\n\ 29 | #\n\ 30 | # Power: With the right parameters, this test catches more GSL\n\ 31 | # generators than any other; however, that count is biased by each of\n\ 32 | # the randomNNN generators having three copies.\n\ 33 | #\n\ 34 | # Limitations: ntuple is required to be a power of 2, because a radix 2\n\ 35 | # algorithm is used to calculate the DCT.\n\ 36 | #\n\ 37 | # False positives: targets are (mostly) calculated exactly, however it\n\ 38 | # will still return false positives when ntuple is small and tsamples is\n\ 39 | # very large. For the default ntuple value of 256, I get bad scores with\n\ 40 | # about 100 million or more tsamples (psamples set to 1).\n\ 41 | #\n\ 42 | # [1] The samples are taken as unsigned integers, and the DC coefficient\n\ 43 | # is adjusted to compensate for this.\n\ 44 | #/\n", 45 | 1, 46 | 50000, 47 | 1, 48 | dab_dct, 49 | 0 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /include/dieharder/marsaglia_tsang_gcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_marsaglia_tsang_gcd test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int marsaglia_tsang_gcd(Test **test,int irun); 9 | 10 | static Dtest marsaglia_tsang_gcd_dtest __attribute__((unused)) = { 11 | "Marsaglia and Tsang GCD Test", 12 | "marsaglia_tsang_gcd", 13 | "\ 14 | #==================================================================\n\ 15 | # Marsaglia and Tsang GCD Test\n\ 16 | #\n\ 17 | # 10^7 tsamples (default) of uint rands u, v are generated and two\n\ 18 | # statistics are generated: their greatest common divisor (GCD) (w)\n\ 19 | # and the number of steps of Euclid's Method required to find it\n\ 20 | # (k). Two tables of frequencies are thus generated -- one for the\n\ 21 | # number of times each value for k in the range 0 to 41 (with counts\n\ 22 | # greater than this range lumped in with the endpoints).\n\ 23 | # The other table is the frequency of occurrence of each GCD w.\n\ 24 | # k is be distributed approximately binomially, but this is useless for\n\ 25 | # the purposes of performing a stringent test. Instead four \"good\"\n\ 26 | # RNGs (gfsr4,mt19937_1999,rndlxs2,taus2) were used to construct a\n\ 27 | # simulated table of high precision probabilities for k (a process that\n\ 28 | # obviously begs the question as to whether or not THESE generators\n\ 29 | # are \"good\" wrt the test). At any rate, they produce very similar tables\n\ 30 | # and pass the test with each other's tables (and are otherwise very\n\ 31 | # different RNGs). The table of probabilities for the gcd distribution is\n\ 32 | # generated dynamically per test (it is easy to compute). Chisq tests\n\ 33 | # on both of these binned distributions yield two p-values per test,\n\ 34 | # and 100 (default) p-values of each are accumulated and subjected to\n\ 35 | # final KS tests and displayed in a histogram.\n\ 36 | #==================================================================\n", 37 | 100, 38 | 10000000, 39 | 2, /* This test returns two statistics */ 40 | marsaglia_tsang_gcd, 41 | 0 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /include/dieharder/rijndael-alg-fst.h: -------------------------------------------------------------------------------- 1 | /** 2 | * rijndael-alg-fst.h 3 | * 4 | * @version 3.0 (December 2000) 5 | * 6 | * Optimised ANSI C code for the Rijndael cipher (now AES) 7 | * 8 | * @author Vincent Rijmen 9 | * @author Antoon Bosselaers 10 | * @author Paulo Barreto 11 | * 12 | * This code is hereby placed in the public domain. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 15 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 23 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 24 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __RIJNDAEL_ALG_FST_H 27 | #define __RIJNDAEL_ALG_FST_H 28 | 29 | #define MAXKC (256/32) 30 | #define MAXKB (256/8) 31 | #define MAXNR 14 32 | 33 | typedef unsigned char u8; 34 | typedef unsigned short u16; 35 | typedef unsigned int u32; 36 | 37 | int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits); 38 | int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits); 39 | void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]); 40 | void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]); 41 | 42 | #ifdef INTERMEDIATE_VALUE_KAT 43 | void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds); 44 | void rijndaelDecryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds); 45 | #endif /* INTERMEDIATE_VALUE_KAT */ 46 | 47 | #endif /* __RIJNDAEL_ALG_FST_H */ 48 | -------------------------------------------------------------------------------- /libdieharder/bauer/rijndael-alg-fst.h: -------------------------------------------------------------------------------- 1 | /** 2 | * rijndael-alg-fst.h 3 | * 4 | * @version 3.0 (December 2000) 5 | * 6 | * Optimised ANSI C code for the Rijndael cipher (now AES) 7 | * 8 | * @author Vincent Rijmen 9 | * @author Antoon Bosselaers 10 | * @author Paulo Barreto 11 | * 12 | * This code is hereby placed in the public domain. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 15 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 23 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 24 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __RIJNDAEL_ALG_FST_H 27 | #define __RIJNDAEL_ALG_FST_H 28 | 29 | #define MAXKC (256/32) 30 | #define MAXKB (256/8) 31 | #define MAXNR 14 32 | 33 | typedef unsigned char u8; 34 | typedef unsigned short u16; 35 | typedef unsigned int u32; 36 | 37 | int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits); 38 | int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits); 39 | void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]); 40 | void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]); 41 | 42 | #ifdef INTERMEDIATE_VALUE_KAT 43 | void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds); 44 | void rijndaelDecryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds); 45 | #endif /* INTERMEDIATE_VALUE_KAT */ 46 | 47 | #endif /* __RIJNDAEL_ALG_FST_H */ 48 | -------------------------------------------------------------------------------- /include/dieharder/brg_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue 16/08/2006 31 | */ 32 | 33 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 34 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 35 | 36 | /* 37 | * Endianness is (now) set in configure.ac, using what is supposedly the 38 | * right/portable way to determine byte order on all platforms. This test 39 | * (and the derived makefiles) pass LITTLE_ENDIAN in as 1 (true) or 0 40 | * (false). We pass this in the defines in Makefile.am, test here, and 41 | * set PLATFORM_BYTE_ORDER without any of the full on any GBT-supporting 42 | * platform, we hope. rgb, for dieharder version. 43 | */ 44 | #ifdef LITTLE_ENDIAN 45 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 46 | #else 47 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 48 | #endif 49 | -------------------------------------------------------------------------------- /include/dieharder/rgb_minimum_distance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rgb_minimum_distance test header 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int rgb_minimum_distance(Test **test,int irun); 9 | 10 | static Dtest rgb_minimum_distance_dtest __attribute__((unused)) = { 11 | "RGB Generalized Minimum Distance Test", 12 | "rgb_minimum_distance", 13 | "#\n\ 14 | # THE GENERALIZED MINIMUM DISTANCE TEST\n\ 15 | #\n\ 16 | # This is the generalized minimum distance test, based on the paper of M.\n\ 17 | # Fischler in the doc directory and private communications. This test\n\ 18 | # utilizes correction terms that are essential in order for the test not\n\ 19 | # to fail for large numbers of trials. It replaces both\n\ 20 | # diehard_2dsphere.c and diehard_3dsphere.c, and generalizes the test\n\ 21 | # itself so that it can be run for any d = 2,3,4,5. There is no\n\ 22 | # fundamental obstacle to running it for d = 1 or d>5, but one would need\n\ 23 | # to compute the expected overlap integrals (q) for the overlapping\n\ 24 | # d-spheres in the higher dimensions. Note that in this test there is no\n\ 25 | # real need to stick to the parameters of Marsaglia. The test by its\n\ 26 | # nature has three controls: n (the number of points used to sample the\n\ 27 | # minimum distance) which determines the granularity of the test -- the\n\ 28 | # approximate length scale probed for an excess of density; p, the usual\n\ 29 | # number of trials; and d the dimension. As Fischler points out, to\n\ 30 | # actually resolve problems with a generator that had areas 20% off the\n\ 31 | # expected density (consistently) in d = 2, n = 8000 (Marsaglia's\n\ 32 | # parameters) would require around 2500 trials, where p = 100 (the old\n\ 33 | # test default) would resolve only consistent deviations of around 1.5\n\ 34 | # times the expected density. By making both of these user selectable\n\ 35 | # parameters, dieharder should be able to test a generator pretty much\n\ 36 | # as thoroughly as one likes subject to the generous constraints\n\ 37 | # associated with the eventual need for still higher order corrections\n\ 38 | # as n and p are made large enough.\n\ 39 | #\n", 40 | 1000, 41 | 10000, 42 | 1, 43 | rgb_minimum_distance, 44 | 0 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /include/dieharder/dieharder_test_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ======================================================================== 3 | * $Id: sts_runs.c 237 2006-08-23 01:33:46Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | * ======================================================================== 7 | */ 8 | 9 | /* 10 | * ======================================================================== 11 | * This program initializes a permanent internal vector of pointers to all 12 | * the tests known to dieharder that generate a pvalue or vector of 13 | * pvalues. With it we abandon our former addressing of tests by source 14 | * (the -d, -r, -s testnumber invocation) in favor of a segmented single 15 | * number. There is initial room for up to 1000 tests, but this can easily 16 | * be increased. 17 | * 18 | * We define the ranges: 19 | * 20 | * 0-99 diehard (or Marsaglia & Tsang) based tests. 21 | * 100-199 the NIST STS 22 | * 200-499 everything else. 23 | * 500-999 reserved for future sets of "named" tests if it seems 24 | * reasonable to use it that way, or straight expansion 25 | * space otherwise. 500 tests will hold us for a while... 26 | * 27 | * ======================================================================== 28 | */ 29 | 30 | /* 31 | * test global vectors and variables for tests. 32 | */ 33 | #define MAXTESTS 1000 34 | 35 | 36 | 37 | void dieharder_test_types(); 38 | 39 | extern Dtest *dh_test_types[MAXTESTS]; 40 | 41 | #define ADD_TEST(t) {if (i==MAXTESTS) abort(); dh_test_types[i] = (t); i++; }; 42 | 43 | /* 44 | * Global shared counters for the new types of rngs in the organization 45 | * defined above. 46 | */ 47 | extern unsigned int dh_num_diehard_tests; /* diehard tests available in dieharder */ 48 | extern unsigned int dh_num_sts_tests; /* STS tests available in dieharder */ 49 | extern unsigned int dh_num_other_tests; /* other tests available in dieharder */ 50 | extern unsigned int dh_num_user_tests; /* user tests added in ui segment */ 51 | extern unsigned int dh_num_tests; /* total tests available in dieharder */ 52 | 53 | 54 | extern Dtest *dh_test; /* global pointer to the current test */ 55 | -------------------------------------------------------------------------------- /include/dieharder/rgb_lagged_sums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an example header file for a test. For existing tests these 3 | * headers are in the library includes already, but this one is an example 4 | * suitable for use as a template. 5 | */ 6 | 7 | /* 8 | * The function needs a prototype. In order to use the standard test 9 | * creation/destruction/execution routines, the prototype should have 10 | * precisely this form. 11 | */ 12 | int rgb_lagged_sums(Test **test,int irun); 13 | 14 | /* 15 | * This is default data for the test at hand. The first field is 16 | * the test name. The second is the test description. The third 17 | * is the default number of p-values generated by a run for display 18 | * in a histogram and to generate a cumulative test p-value using 19 | * Kuiper-Kolmogorov-Smirnov. The fourth is the number of "samples" 20 | * accumulated per test, if relevant (some tests do not permit this 21 | * to be varied). The fifth and final Dtest parameter is the number 22 | * of statistics generated by the test (per test invocation) -- usually 23 | * this will be one but for several it is two and could be more. 24 | */ 25 | static Dtest rgb_lagged_sums_dtest __attribute__((unused)) = { 26 | "RGB Lagged Sum Test", 27 | "rgb_lagged_sum", 28 | "\ 29 | #==================================================================\n\ 30 | # RGB Lagged Sums Test\n\ 31 | # This package contains many very lovely tests. Very few of them,\n\ 32 | # however, test for lagged correlations -- the possibility that\n\ 33 | # the random number generator has a bitlevel correlation after\n\ 34 | # some fixed number of intervening bits.\n\ 35 | #\n\ 36 | # The lagged sums test is therefore very simple. One simply adds up\n\ 37 | # uniform deviates sampled from the rng, skipping lag samples in between\n\ 38 | # each rand used. The mean of tsamples samples thus summed should be\n\ 39 | # 0.5*tsamples. The standard deviation should be sqrt(tsamples/12).\n\ 40 | # The experimental values of the sum are thus converted into a\n\ 41 | # p-value (using the erf()) and a ks-test applied to psamples of them.\n\ 42 | #==================================================================\n", 43 | 100, 44 | 1000000, 45 | 1, 46 | rgb_lagged_sums, 47 | 0 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /dieharder/user_template.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an example header file for a test. For existing tests these 3 | * headers are in the library includes already, but this one is an example 4 | * suitable for use as a template. 5 | */ 6 | 7 | /* 8 | * The function needs a prototype. In order to use the standard test 9 | * creation/destruction/execution routines, the prototype should have 10 | * precisely this form. 11 | */ 12 | int user_template(Test **test,int irun); 13 | 14 | /* 15 | * This is default data for the test at hand. The first field is 16 | * the test name. The second is the test description. The third 17 | * is the default number of p-values generated by a run for display 18 | * in a histogram and to generate a cumulative test p-value using 19 | * Kuiper-Kolmogorov-Smirnov. The fourth is the number of "samples" 20 | * accumulated per test, if relevant (some tests do not permit this 21 | * to be varied). The fifth and final Dtest parameter is the number 22 | * of statistics generated by the test (per test invocation) -- usually 23 | * this will be one but for several it is two and could be more. 24 | */ 25 | static Dtest user_template_dtest __attribute__((unused)) = { 26 | "Example User Test", 27 | "user_template", 28 | "\n\ 29 | #==================================================================\n\ 30 | # Example Dieharder Test\n\ 31 | #\n\ 32 | # Lagged Sum Test\n\ 33 | # This package contains many very lovely tests. Very few of them,\n\ 34 | # however, test for lagged correlations -- the possibility that\n\ 35 | # the random number generator has a bitlevel correlation after\n\ 36 | # some period. Diehard tests, for example, COULD NOT test for this\n\ 37 | # sort of thing with only a few million rands to sample from.\n\ 38 | # The template test is therefore very simple. It takes a user-\n\ 39 | # specified lag (-x lag) and adds up uniform deviates sampled with\n\ 40 | # that lag. The mean of tsamples samples summed should be\n\ 41 | # 0.5*tsamples. The standard deviation should be sqrt(tsamples/12).\n\ 42 | # The experimental values of the sum are thus converted into a\n\ 43 | # p-value (using the erf()) and a ks-test applied to psamples of them.\n\ 44 | #==================================================================\n", 45 | 100, 46 | 100000, 47 | 1, 48 | user_template, 49 | 0 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /include/dieharder/diehard_count_1s_byte.h: -------------------------------------------------------------------------------- 1 | /* 2 | * diehard_count_1s_byte test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int diehard_count_1s_byte(Test **test,int irun); 9 | 10 | static Dtest diehard_count_1s_byte_dtest __attribute__((unused)) = { 11 | "Diehard Count the 1s Test (byte)", 12 | "diehard_count_1s_byte", 13 | "\ 14 | #==================================================================\n\ 15 | # Diehard Count the 1s Test (byte) (modified).\n\ 16 | # This is the COUNT-THE-1's TEST for specific bytes. \n\ 17 | # Consider the file under test as a stream of 32-bit integers. \n\ 18 | # From each integer, a specific byte is chosen , say the left- \n\ 19 | # most:: bits 1 to 8. Each byte can contain from 0 to 8 1's, \n\ 20 | # with probabilitie 1,8,28,56,70,56,28,8,1 over 256. Now let \n\ 21 | # the specified bytes from successive integers provide a string \n\ 22 | # of (overlapping) 5-letter words, each \"letter\" taking values \n\ 23 | # A,B,C,D,E. The letters are determined by the number of 1's, \n\ 24 | # in that byte:: 0,1,or 2 ---> A, 3 ---> B, 4 ---> C, 5 ---> D,\n\ 25 | # and 6,7 or 8 ---> E. Thus we have a monkey at a typewriter \n\ 26 | # hitting five keys with with various probabilities:: 37,56,70,\n\ 27 | # 56,37 over 256. There are 5^5 possible 5-letter words, and \n\ 28 | # from a string of 256,000 (overlapping) 5-letter words, counts \n\ 29 | # are made on the frequencies for each word. The quadratic form \n\ 30 | # in the weak inverse of the covariance matrix of the cell \n\ 31 | # counts provides a chisquare test:: Q5-Q4, the difference of \n\ 32 | # the naive Pearson sums of (OBS-EXP)^2/EXP on counts for 5- \n\ 33 | # and 4-letter cell counts. \n\ 34 | # \n\ 35 | # Note: We actually cycle samples over all 0-31 bit offsets, so \n\ 36 | # that if there is a problem with any particular offset it has \n\ 37 | # a chance of being observed. One can imagine problems with odd \n\ 38 | # offsets but not even, for example, or only with the offset 7.\n\ 39 | # tsamples and psamples can be freely varied, but you'll likely \n\ 40 | # need tsamples >> 100,000 to have enough to get a reliable kstest \n\ 41 | # result. \n\ 42 | #==================================================================\n", 43 | 100, 44 | 256000, 45 | 1, 46 | diehard_count_1s_byte, 47 | 0 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /manual/Makefile.am: -------------------------------------------------------------------------------- 1 | SOURCE = dieharder.tex 2 | VERSION = 0.1 3 | RELEASE = 1 4 | 5 | SVNTREE = $(HOME)/Src/svn-tree 6 | SVNPATH = $(SVNTREE)/dieharder 7 | SVNTIME = $(HOME/Src/Projects/dieharder/dieharder.svn.time) 8 | 9 | # The list of includes are things required for the build to work. Examples 10 | # might be included .tex or .sty files, embedded .eps files, and so forth. 11 | # Naturally, anything on this list should be in the SVN tree. 12 | # FIGS = $(shell ls *.fig 2>&1 | grep -v "No such file or directory" | sed -e "/\/bin\/ls:/d") 13 | # FEPS = $(FIGS:.fig=.eps) 14 | # INCLUDE = $(FIGS) 15 | 16 | # Source(s) and production objects. 17 | SOURCES = $(SOURCE) 18 | LOGS = $(SOURCE:.tex=.log) 19 | TOC = $(SOURCE:.tex=.toc) 20 | AUX = $(SOURCE:.tex=.aux) 21 | ERR = $(SOURCE:.tex=.err) 22 | DVI = $(SOURCE:.tex=.dvi) 23 | PS = $(SOURCE:.tex=.ps) 24 | PDF = $(SOURCE:.tex=.pdf) 25 | A4PS = $(SOURCE:.tex=.a4.ps) 26 | A4PDF = $(SOURCE:.tex=.a4.pdf) 27 | HTMLDIR = $(SOURCE:.tex=) 28 | 29 | # Build targets (from rules) 30 | all: $(PDF) 31 | ps: $(DVI) $(PS) 32 | pdf: $(DVI) $(PS) $(PDF) 33 | a4ps: $(DVI) $(A4PS) 34 | a4pdf: $(DVI) $(A4PS) $(A4PDF) 35 | tar: $(TAR) 36 | tgz: $(TGZ) 37 | 38 | # 39 | # These should run in the doc directory, although a commit one level up 40 | # will work too... 41 | # 42 | svn: 43 | echo "New Checkin `date`" >> $(SVNTIME) # Will force a commit and increment revision 44 | svn commit . 45 | cat $(SVNTIME) | \ 46 | sed -e '/^New Checkin/d' >> $(SVNTIME).tmp 47 | mv $(SVNTIME).tmp $(SVNTIME) 48 | 49 | # Clean up all the junk build files and output formats to save space. 50 | clean: 51 | rm -f $(DVI) $(AUX) $(LOGS) $(TOC) $(ERR) $(PS) $(PDF) 52 | 53 | install: $(PDF) 54 | cp $(PDF) .. 55 | 56 | # 57 | # RULES FOR BUILDING STANDARD TARGETS 58 | # 59 | # Rule for making dvi out of tex. Do it twice to build table of contents 60 | # and resolve forward references. 61 | %.dvi:%.tex $(SOURCES) 62 | latex $< $@ 63 | latex $< $@ 64 | 65 | # Rule for making postscript image 66 | %.ps:%.dvi 67 | dvips -Pamz -Pcmz -o $@ $< 68 | 69 | # Rule for making pdf image 70 | %.pdf:%.ps 71 | ps2pdf $< 72 | 73 | # Rule for making postscript image 74 | %.a4.ps:%.dvi 75 | dvips -Pamz -Pcmz -t A4 -o $@ $< 76 | 77 | # Rule for making pdf image 78 | %.a4.pdf:%.a4.ps 79 | ps2pdf $< 80 | 81 | # Rule for making .fig->.eps 82 | %.eps:%.fig 83 | fig2dev -L eps $< > $@ 84 | 85 | -------------------------------------------------------------------------------- /libdieharder/convertoperm.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | 4 | use FileHandle; 5 | my $i=1; 6 | my $j=1; 7 | 8 | $r[$i][$j] = 1; 9 | 10 | 11 | $firstcall = 1; 12 | 13 | # Open op5dat.for 14 | open(IN,"op5dat.for") || die "Sorry, I couldn't open op5dat.for\n"; 15 | open(OUT,">op5dat") || die "Sorry, I couldn't open op5dat.\n"; 16 | autoflush OUT 1; 17 | # Write to the file... 18 | printf OUT "#========================================================================\n"; 19 | printf OUT "# R and S data ported from diehard and put into C-style matrix form\n"; 20 | printf OUT "#========================================================================\n"; 21 | # ...and also output to console, just for fun. 22 | printf "#========================================================================\n"; 23 | printf "# R and S data ported from diehard and put into C-style matrix form\n"; 24 | printf "#========================================================================\n"; 25 | 26 | # Initialize the table (read in the whole thing in order) 27 | nextrs(); 28 | for($i=0;$i<60;$i++) { 29 | for($j=$i;$j<60;$j++){ 30 | $r[$i][$j] = nextrs(); 31 | $r[$j][$i] = $r[$i][$j]; 32 | } 33 | } 34 | 35 | print OUT "static int r[60][60] = {\n"; 36 | for($i=0;$i<60;$i++) { 37 | print OUT " {"; 38 | for($j=0;$j<59;$j++){ 39 | printf OUT (" %10d,",$r[$i][$j]); 40 | } 41 | if($i<59){ 42 | printf OUT (" %10d},\n",$r[$i][59]); 43 | } else { 44 | printf OUT (" %10d}\n",$r[$i][59]); 45 | } 46 | } 47 | print OUT "};\n"; 48 | 49 | for($i=0;$i<60;$i++) { 50 | for($j=$i;$j<60;$j++){ 51 | $s[$i][$j] = nextrs(); 52 | $s[$j][$i] = $s[$i][$j]; 53 | } 54 | } 55 | 56 | print OUT "static int s[60][60] = {\n"; 57 | for($i=0;$i<60;$i++) { 58 | print OUT " {"; 59 | for($j=0;$j<59;$j++){ 60 | printf OUT (" %10d,",$s[$i][$j]); 61 | } 62 | if($i<59){ 63 | printf OUT (" %10d},\n",$r[$i][59]); 64 | } else { 65 | printf OUT (" %10d}\n",$r[$i][59]); 66 | } 67 | } 68 | print OUT "};\n"; 69 | 70 | exit; 71 | 72 | 73 | sub nextrs { 74 | if($firstcall == 1){ 75 | my $irs = 0; 76 | my $jrs; 77 | while(){ 78 | chop; 79 | @field = split(/\s+/,$_); 80 | $fields = @field; 81 | for($jrs=1;$jrs<$fields;$jrs++){ 82 | $rs[$irs] = $field[$jrs]; 83 | $irs++; 84 | } 85 | } 86 | # print "# Read in $irs values\n"; 87 | $irs = 0; 88 | $firstcall = 0; 89 | return; 90 | } 91 | 92 | return $rs[$irs++]; 93 | 94 | } 95 | 96 | -------------------------------------------------------------------------------- /include/dieharder/dab_opso2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_opso2 test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_opso2(Test **test, int irun); 9 | 10 | static Dtest dab_opso2_dtest __attribute__((unused)) = { 11 | "DAB OPSO2", 12 | "dab_opso2", 13 | "\ 14 | #==================================================================\n\ 15 | # DAB OPSO2 Test\n\ 16 | # This test is misnamed. It is an evolution of the OPSO test from\n\ 17 | # the original Diehard program. However, it does not use\n\ 18 | # DAB OPSO2 Test\n\ 19 | # This test is misnamed. It is an evolution of the OPSO test from\n\ 20 | # the original Diehard program. However, it does not use\n\ 21 | # overlapping samples. Additionally, it returns two p-values,\n\ 22 | # the second of which follows the Pairs-Sparse-Occupancy part of\n\ 23 | # the name. The first p-value effectively takes both letters from\n\ 24 | # the same input word. However, that isn't any different from\n\ 25 | # having 1-letter words, where each letter is twice as long.\n\ 26 | # \n\ 27 | # This verion uses 2^24 slots. The first p-value thus takes 24\n\ 28 | # bits directly from each input word. The second p-value is based\n\ 29 | # on two 12-bit letters from each of two words; each pair of input\n\ 30 | # words will produce two output \"words\".\n\ 31 | # \n\ 32 | # This test will give a false positive for all generators with an\n\ 33 | # output word of less than 24 bits.\n\ 34 | # \n\ 35 | # Note tsamples is set to 2^26 = 67108864, and cannot be varied.\n\ 36 | #\n\ 37 | # Diehard Overlapping Pairs Sparse Occupance (OPSO)\n\ 38 | # The OPSO test considers 2-letter words from an alphabet of \n\ 39 | # 1024 letters. Each letter is determined by a specified ten \n\ 40 | # bits from a 32-bit integer in the sequence to be tested. OPSO \n\ 41 | # generates 2^21 (overlapping) 2-letter words (from 2^21+1 \n\ 42 | # \"keystrokes\") and counts the number of missing words---that \n\ 43 | # is 2-letter words which do not appear in the entire sequence. \n\ 44 | # That count should be very close to normally distributed with \n\ 45 | # mean 141,909, sigma 290. Thus (missingwrds-141909)/290 should \n\ 46 | # be a standard normal variable. The OPSO test takes 32 bits at \n\ 47 | # a time from the test file and uses a designated set of ten \n\ 48 | # consecutive bits. It then restarts the file for the next de- \n\ 49 | # signated 10 bits, and so on. \n\ 50 | # \n\ 51 | #==================================================================\n", 52 | 1, 53 | 67108864, 54 | 2, 55 | dab_opso2, 56 | 0 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /libdieharder/rgb_persist.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: rgb_persist.c 250 2006-10-10 05:02:26Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | */ 6 | 7 | /* 8 | *======================================================================== 9 | * This is a test that checks to see if all the bits returned by the 10 | * rng change. Surprisingly, several generators have bits that do NOT 11 | * change, hence the test. It also reveals tests that for whatever reason 12 | * return less than the expected uint number of bits (32) as unchanging 13 | * high bits 14 | * 15 | * This (and all further rgb_ tests) are "my own". Some of them may turn 16 | * out to be formally equivalent to diehard or sts or knuth tests in the 17 | * specific sense that failure in one always matches or precedes failure 18 | * in the other. 19 | *======================================================================== 20 | */ 21 | 22 | #include 23 | 24 | int rgb_persist(Test **test, Rgb_Persist *persist) 25 | { 26 | 27 | uint last_rand; 28 | int i,j; 29 | 30 | /* 31 | * Now go through the list and dump the numbers several ways. 32 | */ 33 | if(bits > 32) { 34 | persist->nbits = 32; 35 | } else { 36 | persist->nbits = bits; 37 | } 38 | 39 | persist->cumulative_mask = 0; 40 | for(j=0;jand_mask = ~(last_rand ^ rgb_persist_rand_uint[0]); 56 | for(i=0;i<256;i++){ 57 | if(verbose){ 58 | printf("rgb_persist_rand_uint[%d] = %u = ",i,rgb_persist_rand_uint[i]); 59 | dumpbits(&rgb_persist_rand_uint[i],persist->nbits); 60 | printf("\n"); 61 | } 62 | 63 | /* 64 | * Now we make a mask of bits that coincide. Logic 41, where are you? 65 | */ 66 | persist->and_mask = persist->and_mask & (~(last_rand ^ rgb_persist_rand_uint[i])); 67 | if(verbose){ 68 | printf("and_mask = %u = ",persist->and_mask); 69 | dumpbits(&persist->and_mask,persist->nbits); 70 | printf("\n"); 71 | } 72 | 73 | } 74 | persist->and_mask = persist->and_mask & rmax_mask; 75 | persist->cumulative_mask = persist->cumulative_mask | persist->and_mask; 76 | } 77 | 78 | return(0); 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /libdieharder/bauer/rng_aes.c: -------------------------------------------------------------------------------- 1 | /* rng_es 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include 21 | #include "rijndael-alg-fst.h" 22 | 23 | // State blocks = 1 for weakest form 24 | #define STATE_BLOCKS (1) /* MUST be 1 for AES */ 25 | #define BLOCKS_SIZE (16 * STATE_BLOCKS) 26 | #define NR 10 27 | 28 | /* 29 | * This is a wrapping of the AES algorithm as a generator 30 | */ 31 | 32 | typedef struct { 33 | u32 rk[4*(NR + 1)]; 34 | unsigned char block[BLOCKS_SIZE]; 35 | short int pos; 36 | } AES_state_t; 37 | 38 | unsigned long int aes_get (void *vstate); 39 | double aes_get_double (void *vstate); 40 | void aes_set (void *vstate, unsigned long int s); 41 | 42 | unsigned long int aes_get (void *vstate) { 43 | AES_state_t *state = vstate; 44 | unsigned int ret; 45 | 46 | if (state->pos + sizeof(ret) > BLOCKS_SIZE) { 47 | rijndaelEncrypt(state->rk, NR, state->block, state->block); 48 | state->pos = 0; 49 | } 50 | 51 | ret = *((unsigned int *) (state->block + state->pos)); 52 | state->pos += sizeof(ret); 53 | 54 | // ret &= 0x7fffffff; 55 | return(ret); 56 | } 57 | 58 | 59 | double aes_get_double (void *vstate) { 60 | // return aes_get_long(vstate) / (double) ULONG_MAX; 61 | return (double) aes_get(vstate) / (double) (UINT_MAX >> 0); 62 | } 63 | 64 | void aes_set (void *vstate, unsigned long int s) { 65 | AES_state_t *state = vstate; 66 | int i; 67 | u8 key[16]; 68 | 69 | memset(state, 0, sizeof(*state)); // Zero pos and block 70 | 71 | for (i = 0; i < 16; i++) { 72 | key[i] = (u8) (112 + i + (s >> i)); 73 | } 74 | rijndaelKeySetupEnc(state->rk, key, 128); 75 | rijndaelEncrypt(state->rk, NR, state->block, state->block); 76 | 77 | return; 78 | } 79 | 80 | static const gsl_rng_type aes_type = { 81 | "AES_OFB", /* name */ 82 | UINT_MAX>>0, // UINT_MAX, /* RAND_MAX */ 83 | 0, /* RAND_MIN */ 84 | sizeof (AES_state_t), 85 | &aes_set, 86 | &aes_get, 87 | &aes_get_double}; 88 | 89 | const gsl_rng_type *gsl_rng_aes = &aes_type; 90 | 91 | -------------------------------------------------------------------------------- /include/dieharder/dab_birthdays1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dab_birthdays1 test header. 3 | */ 4 | 5 | /* 6 | * function prototype 7 | */ 8 | int dab_birthdays1(Test **test, int irun); 9 | 10 | static Dtest dab_birthdays1_dtest __attribute__((unused)) = { 11 | "DAB Diehard Birthdays Test", 12 | "dab_birthdays1", 13 | "\n\ 14 | #==================================================================\n\ 15 | # Diehard \"Birthdays\" test (modified).\n\ 16 | # This is a version of the Diehard Birthdays test, modified from the\n\ 17 | # original Dieharder implementation of it.\n\ 18 | # \n\ 19 | # This is a BIRTHDAY SPACINGS TEST\n\ 20 | # Choose m birthdays in a year of n days. List the spacings between \n\ 21 | # the birthdays. If j is the number of values that occur more than \n\ 22 | # once in that list, then j is asympotically Poisson distributed with \n\ 23 | # mean lambda = m^3/(4n). A Chi-Sq test is performed comparing the \n\ 24 | # seen distribution of repeated spacings to the Poisson distribution. \n\ 25 | # Simulations show that the approximation is better for larger n and \n\ 26 | # smaller lambda. However, since for any given run j must be an \n\ 27 | # integer, a small lambda value requires more runs to build up a good \n\ 28 | # statistic. This test uses m=1700 as the default, but it may \n\ 29 | # changed (via the -n (ntuple) option), up to a maximum value of \n\ 30 | # 4096. The value of n is fixed by the choice of generator, with \n\ 31 | # n=2^r, where r is the number of bits per word in the generator's \n\ 32 | # output (a maximum of 32 for this version of Dieharder). This test \n\ 33 | # prefers a larger t-count (-t option) and p-value samples set to 1 \n\ 34 | # (-p 1, which is the default).\n\ 35 | # \n\ 36 | # Be careful when running this test against generators with reduced \n\ 37 | # word sizes, as it may give false positives. When it doubt, check \n\ 38 | # against an assumed good generator that is set to produce the same \n\ 39 | # size output. As an example, for testing a generator with an output \n\ 40 | # size of 20 bits, using \"-n 50 -t 8000\" produced a test that \n\ 41 | # repeated passed an assumed good generator at \"-p 100\", but had \n\ 42 | # trouble at \"-p 500\". Alternately, raising the t-count also shows \n\ 43 | # that m of 50 isn't low enough to give a good approximation. For \n\ 44 | # long tests of generators with an output size smaller than 30 bits, \n\ 45 | # producing the target by simulation instead of relying on the \n\ 46 | # Poisson approximation will probably be necessary.\n\ 47 | # \n\ 48 | #==================================================================\n", 49 | 1, 50 | 2000, 51 | 1, 52 | dab_birthdays1, 53 | 0 54 | }; 55 | 56 | /* 57 | * Global variables 58 | uint dab_birthdays1_nms,dab_birthdays1_nbits; 59 | uint *dab_birthdays1_rand_uint; 60 | */ 61 | -------------------------------------------------------------------------------- /libdieharder/rng_XOR.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * rng_XOR.c 4 | * 5 | * This generator takes a list of generators on the dieharder 6 | * command line and XOR's their output together. 7 | *======================================================================== 8 | */ 9 | 10 | #include 11 | 12 | /* 13 | * This is a special XOR generator that takes a list of GSL 14 | * wrapped rngs and XOR's their uint output together to produce 15 | * each new random number. Note that it SKIPS THE FIRST ONE which 16 | * MUST be the XOR rng itself. So there have to be at least two -g X 17 | * stanzas on the command line to use XOR, and if there aren't three 18 | * or more it doesn't "do" anything but use the second one. 19 | */ 20 | static unsigned long int XOR_get (void *vstate); 21 | static double XOR_get_double (void *vstate); 22 | static void XOR_set (void *vstate, unsigned long int s); 23 | 24 | typedef struct { 25 | /* 26 | * internal gsl random number generator vector 27 | */ 28 | gsl_rng *grngs[GVECMAX]; 29 | unsigned int XOR_rnd; 30 | } XOR_state_t; 31 | 32 | static inline unsigned long int 33 | XOR_get (void *vstate) 34 | { 35 | XOR_state_t *state = (XOR_state_t *) vstate; 36 | int i; 37 | 38 | /* 39 | * There is always this one, or we are in deep trouble. I am going 40 | * to have to decorate this code with error checks... 41 | */ 42 | state->XOR_rnd = gsl_rng_get(state->grngs[1]); 43 | for(i=1;iXOR_rnd ^= gsl_rng_get(state->grngs[i]); 45 | } 46 | return state->XOR_rnd; 47 | 48 | } 49 | 50 | static double 51 | XOR_get_double (void *vstate) 52 | { 53 | return XOR_get (vstate) / (double) UINT_MAX; 54 | } 55 | 56 | static void XOR_set (void *vstate, unsigned long int s) { 57 | 58 | XOR_state_t *state = (XOR_state_t *) vstate; 59 | int i; 60 | uint seed_seed; 61 | 62 | /* 63 | * OK, here's how it works. grngs[0] is set to mt19937_1999, seeded 64 | * as per usual, and used (ONLY) to see the remaining generators. 65 | * The remaining generators. 66 | */ 67 | state->grngs[0] = gsl_rng_alloc(dh_rng_types[14]); 68 | seed_seed = s; 69 | gsl_rng_set(state->grngs[0],seed_seed); 70 | for(i=1;igrngs[i] = gsl_rng_alloc(dh_rng_types[gnumbs[i]]); 78 | gsl_rng_set(state->grngs[i],gsl_rng_get(state->grngs[0])); 79 | 80 | } 81 | 82 | } 83 | 84 | static const gsl_rng_type XOR_type = 85 | {"XOR (supergenerator)", /* name */ 86 | UINT_MAX, /* RAND_MAX */ 87 | 0, /* RAND_MIN */ 88 | sizeof (XOR_state_t), 89 | &XOR_set, 90 | &XOR_get, 91 | &XOR_get_double}; 92 | 93 | const gsl_rng_type *gsl_rng_XOR = &XOR_type; 94 | -------------------------------------------------------------------------------- /manual/crown_quarto.tex: -------------------------------------------------------------------------------- 1 | \usepackage{epsfig} 2 | \usepackage{html} 3 | \usepackage{geometry} 4 | \usepackage{hyperref} 5 | 6 | % Standard 6x9 trade paperback 7 | % This layout works "perfectly" for lulu. 8 | 9 | % Set paper size 10 | \geometry{paperwidth=7.444in,paperheight=9.681in} 11 | 12 | % set left/right margins for binding 13 | \geometry{twoside} 14 | 15 | % Specify the four OUTER margins, only -- let header, footer, etc live 16 | % within this space and do not otherwise specify them. 17 | \geometry{left=1.60in,right=0.5in,top=0.75in,bottom=0.75in} 18 | 19 | % I'm not certain, but I think that this helps with fonts and passing 20 | % the pagesize through to ps2pdf. 21 | \geometry{dvips} 22 | 23 | % The following are individual preferences, adjust to taste. 24 | 25 | % I like a small gap between paragraphs to improve readability. 26 | \parskip = 0.075in 27 | 28 | % This penalizes breaking things at the end of pages. 29 | \widowpenalty=300 30 | \clubpenalty=300 31 | 32 | % Similarly, I like having a bit more than single spacing to improve 33 | % readability. 34 | \renewcommand{\baselinestretch}{1.1} 35 | 36 | % I find the following to be useful in text layout. 37 | \newcommand{\ind}{\hspace{5 em}} 38 | \newcommand{\vsfill}{\vspace*{\fill}} 39 | \newcommand{\pagefill}{\vsfill \newpage \vsfill} 40 | 41 | % \blankpage is more than useful, it is essential. A lulu book needs 42 | % the FIRST page to be a TITLE page, probably laid out by hand 43 | % (\maketitle just doesn't do very well with it). \pagestyle should be 44 | % empty. Page TWO should be BLANK. Page THREE should be a COPYRIGHT 45 | % page, plus any acknowledgements or license restrictions desired. Page 46 | % FOUR should be BLANK. Alternate odd (content) even (blank) pages up 47 | % to the table of contents. Turn on \pagestyle headings, and 48 | % choose \pagenumbering{roman} for the TOC and possibly the preface, if 49 | % any. Make sure that TOC starts on an odd page (facing the reader on 50 | % the right hand page) -- add blank page(s) as needed to pad things out 51 | % so that this works out. ONCE YOU ARE IN THE MAIN TEXT, the \chapter 52 | % macro will arrange this for you and you can stop. Finally, when you 53 | % start the main text, reset the page counter to 1, set page numbering 54 | % to arabic, and deal with page headers however you like. The default 55 | % is often ok, but there are nice styles you can include to give you 56 | % better (even complete) control of the headers. I personally favor 57 | % having a "free" web version of the book available clearly marked "for 58 | % on-screen viewing only" that directs a user to the lulu site for 59 | % possible book purchase in the header or footer, for example... but 60 | % only in the online PDF. This may require the use of autoconf or 61 | % make/sed to hack a line or two in this very style file to accomplish 62 | % automagically. 63 | \newcommand{\blankpage}{\newpage \vsfill \newpage} 64 | 65 | -------------------------------------------------------------------------------- /libdieharder/rng_aes.c: -------------------------------------------------------------------------------- 1 | /* rng_es 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | // State blocks = 1 for weakest form 24 | #define STATE_BLOCKS (1) /* MUST be 1 for AES */ 25 | #define BLOCKS_SIZE (16 * STATE_BLOCKS) 26 | #define NR 10 27 | 28 | /* 29 | * This is a wrapping of the AES algorithm as a generator 30 | */ 31 | 32 | typedef struct { 33 | u32 rk[4*(NR + 1)]; 34 | unsigned char block[BLOCKS_SIZE]; 35 | short int pos; 36 | } AES_state_t; 37 | 38 | unsigned long int aes_get (void *vstate); 39 | double aes_get_double (void *vstate); 40 | void aes_set (void *vstate, unsigned long int s); 41 | 42 | unsigned long int aes_get (void *vstate) { 43 | AES_state_t *state = vstate; 44 | unsigned int ret; 45 | 46 | if (state->pos + sizeof(ret) > BLOCKS_SIZE) { 47 | rijndaelEncrypt(state->rk, NR, state->block, state->block); 48 | state->pos = 0; 49 | } 50 | 51 | ret = *((unsigned int *) (state->block + state->pos)); 52 | state->pos += sizeof(ret); 53 | 54 | // ret &= 0x7fffffff; 55 | return(ret); 56 | } 57 | 58 | 59 | double aes_get_double (void *vstate) { 60 | // return aes_get_long(vstate) / (double) ULONG_MAX; 61 | return (double) aes_get(vstate) / (double) (UINT_MAX >> 0); 62 | } 63 | 64 | void aes_set (void *vstate, unsigned long int s) { 65 | AES_state_t *state = vstate; 66 | int i; 67 | u8 key[16]; 68 | 69 | memset(state, 0, sizeof(*state)); // Zero pos and block 70 | 71 | /* Make sure to use all bits of s in the key: 72 | * (5 * i) % 26 => {0,5,10,15,20,25,4,9,14,19,24,3,8,13,18,23} 73 | * */ 74 | for (i = 0; i < 16; i++) { 75 | key[i] = (u8) (112 + i + (s >> ((5 * i) % 26))); 76 | } 77 | rijndaelKeySetupEnc(state->rk, key, 128); 78 | rijndaelEncrypt(state->rk, NR, state->block, state->block); 79 | 80 | return; 81 | } 82 | 83 | static const gsl_rng_type aes_type = { 84 | "AES_OFB", /* name */ 85 | UINT_MAX>>0, // UINT_MAX, /* RAND_MAX */ 86 | 0, /* RAND_MIN */ 87 | sizeof (AES_state_t), 88 | &aes_set, 89 | &aes_get, 90 | &aes_get_double}; 91 | 92 | const gsl_rng_type *gsl_rng_aes = &aes_type; 93 | 94 | -------------------------------------------------------------------------------- /dieharder/dieharder.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: dieharder.h 529 2011-04-01 17:49:31Z rgbatduke $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | 9 | #include "copyright.h" 10 | 11 | /* To enable large file support */ 12 | #define _FILE_OFFSET_BITS 64 13 | 14 | #include 15 | 16 | /* 17 | * Flags and variables to control all output formatting etc. tflag_default 18 | * is set in set_globals to a default to be used if -T 0 is selected. 19 | * tflag is otherwise accumulated from a series of -T FLAG calls, where 20 | * flag can be either numerical or a field/control name. table_separator 21 | * allows a user to pick their favorite field separator in the final output 22 | * table: a blank is easy to parse, a | is easy to read, a , is easy to 23 | * import into a spreadsheet (after filtering away e.g. # lines). We make 24 | * blank the default because it is hard to specify a blank on the CL but 25 | * easy to specify the others? 26 | */ 27 | extern unsigned int tflag,tflag_default; 28 | extern char table_separator; 29 | #include "output.h" 30 | 31 | /* 32 | * Variables to handle test selection. parsecl can EITHER be fed a 33 | * test number OR a test name; we have to sort that out when we 34 | * choose a test. 35 | */ 36 | extern int dtest_num; 37 | extern char dtest_name[128]; 38 | extern char generator_name[128]; 39 | 40 | /* 41 | * user_template sources are here, not in library 42 | */ 43 | #include "user_template.h" 44 | 45 | extern double rng_avg_time_nsec,rng_rands_per_second; 46 | extern double strategy; 47 | 48 | #ifdef RDIEHARDER 49 | Test **rdh_testptr; /* kludge: need a global to report back to R */ 50 | Dtest *rdh_dtestptr; /* kludge: need a global to report back to R */ 51 | #endif 52 | 53 | void list_rngs(); 54 | void list_tests(); 55 | void output_rnds(); 56 | void Exit(int); 57 | void time_rng(); 58 | void set_globals(); 59 | void choose_rng(); 60 | int execute_test(int); 61 | void run_all_tests(); 62 | void run_test(); 63 | void add_ui_rngs(); 64 | void parsecl(int argc, char **argv); 65 | void output(Dtest *dtest,Test **test); 66 | void show_test_header(Dtest *dtest,Test **test); 67 | void show_test_header_debug(Dtest *dtest,Test **test); 68 | void test_header(Dtest *dtest); 69 | void show_test_results(Dtest *dtest,Test **test); 70 | void show_test_results_debut(Dtest *dtest,Test **test); 71 | void test_footer(Dtest *dtest, double pvalue, double *pvalues); 72 | 73 | /* 74 | * List new rng types to be added in startup.c. Use "empty" or 75 | * libdieharder rng sources as template, uncomment/clone the lines that 76 | * add your own type(s) in startup.c. Consider sending "good" generators 77 | * that pass all or most tests or "classic" generators good or bad that 78 | * people might want to test back to me to include in libdieharder. 79 | */ 80 | GSL_VAR const gsl_rng_type *gsl_rng_empty_random; 81 | 82 | 83 | -------------------------------------------------------------------------------- /dieharder/Makefile.am: -------------------------------------------------------------------------------- 1 | #======================================================================== 2 | # This is a Makefile for the dieharder tty application, part of the 3 | # overall dieharder package. It has a very abbreviated set of targets. 4 | # 5 | # make alone should build the application. 6 | # 7 | # make clean deletes the application and all object files 8 | # make install installs application and a man page 9 | # make printout prints out all source and include files 10 | # 11 | # These two commands execute in the toplevel project directory only. 12 | # make svn does a svn commit and creates the timestamp $(SVN) 13 | # make sync does a svn commit and rsyncs to list of hosts 14 | #======================================================================== 15 | 16 | # This is automagically set in the toplevel build. Do not edit by 17 | # hand. 18 | VERSION=@VERSION@ 19 | 20 | #======================================================================== 21 | # Define all sources. Note that this little trick will get ALL 22 | # the source files in the working directory, which must not be empty 23 | # Alas, GBT complains just a bit about the shell commands... 24 | #======================================================================== 25 | # dieharder_SOURCES = $(shell ls *.c 2>&1 | sed -e "/\/bin\/ls:/d") 26 | # SRCINCLUDES = $(shell ls *.h 2>&1 | sed -e "/\/bin\/ls:/d") 27 | bin_PROGRAMS = dieharder 28 | man1_MANS = dieharder.1 29 | dieharder_LDADD = ../libdieharder/libdieharder.la 30 | dieharder_SOURCES = \ 31 | add_ui_rngs.c \ 32 | add_ui_tests.c \ 33 | choose_rng.c \ 34 | dieharder.c \ 35 | dieharder_exit.c \ 36 | help.c \ 37 | list_rngs.c \ 38 | list_tests.c \ 39 | output.c output.h \ 40 | output_rnds.c \ 41 | parsecl.c \ 42 | rdieharder.c \ 43 | run_all_tests.c \ 44 | run_test.c \ 45 | set_globals.c \ 46 | testbits.c \ 47 | time_rng.c \ 48 | user_template.c \ 49 | globals.c 50 | 51 | # rng_empty_random.c \ 52 | # run_rgb_bitdist.c 53 | # run_rgb_lagged_sums.c 54 | # run_rgb_minimum_distance.c 55 | # run_rgb_permutations.c 56 | # run_rgb_persist.c 57 | # run_rgb_timing.c 58 | 59 | DEFINES = -DVERSION=$(VERSION) 60 | 61 | #======================================================================== 62 | # Define parameters and directives needed in compile/link steps. 63 | #======================================================================== 64 | # C Compiler 65 | # CC = gcc 66 | 67 | # Compile flags (use fairly standard -O3 as default) 68 | AM_CPPFLAGS = -I ${top_srcdir}/include $(DEFINES) 69 | AM_CFLAGS = -O3 70 | 71 | # Load flags (optional) 72 | # To build a completely static dieharder, uncomment the following line. 73 | # AM_LDFLAGS = -all-static 74 | AM_LDFLAGS = 75 | 76 | #======================================================================== 77 | # The only safe place to do svn commits is in the toplevel directory 78 | #======================================================================== 79 | SVNTREE = $(HOME)/Src/svn-tree 80 | SVNPATH = $(SVNTREE)/dieharder 81 | SVNTIME = dieharder.svn.time) 82 | svn: 83 | (cd ..;make svn) 84 | 85 | sync: 86 | (cd ..;make sync) 87 | -------------------------------------------------------------------------------- /dieharder/validate_1000.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This script runs all the tests the hard way, with more psamples. Ones 4 | # that fail are probably BAD TESTS given that it is difficult to conclude 5 | # that this is likely to be a bad generator. It passes all tests with their 6 | # default number of psamples (usually 100). 7 | 8 | # Diehard tests 9 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 0 -D default -D histogram 10 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 1 -D default -D -5 -D histogram 11 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 2 -D default -D -5 -D histogram 12 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 3 -D default -D -5 -D histogram 13 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 4 -D default -D -5 -D histogram 14 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 5 -D default -D -5 -D histogram 15 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 6 -D default -D -5 -D histogram 16 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 7 -D default -D -5 -D histogram 17 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 8 -D default -D -5 -D histogram 18 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 9 -D default -D -5 -D histogram 19 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 10 -D default -D -5 -D histogram 20 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 11 -D default -D -5 -D histogram 21 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 12 -D default -D -5 -D histogram 22 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 13 -D default -D -5 -D histogram 23 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 14 -D default -D -5 -D histogram 24 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 15 -D default -D -5 -D histogram 25 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 16 -D default -D -5 -D histogram 26 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 17 -D default -D -5 -D histogram 27 | # STS tests. Several of these require runs over ntuples 28 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 100 -D default -D -5 -D histogram 29 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 101 -D default -D -5 -D histogram 30 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 102 -D default -D -5 -D histogram 31 | # rgb tests. Several of these require runs over ntuples or other additional 32 | # arguments. 33 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 200 -D default -D -5 -D histogram 34 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 201 -D default -D -5 -D histogram 35 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 202 -D default -D -5 -D histogram 36 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -p 1000 -d 203 -D default -D -5 -D histogram 37 | cat /dev/zero | aespipe -P aeskey | ./dieharder -g 200 -t 1000 -p 1000 -d 204 -D default -D -5 -D histogram 38 | -------------------------------------------------------------------------------- /libdieharder/sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: sample.c 223 2006-08-17 06:19:38Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * See also accompanying file STS.COPYING 6 | * 7 | */ 8 | 9 | /* 10 | *======================================================================== 11 | * This routine generates "samples" p-values from the test routines, where 12 | * each test routine is a double function that returns a single 13 | * p-value. The p-value returned can be made "independent" by optionally 14 | * reseeding the rng for each test call according to the -i flag. 15 | * 16 | * The p-values are packed into a vector. This vector is subjected to 17 | * analysis to ensure that it is uniform. Minimally this analysis 18 | * consists of a straightforward Kuiper Kolmogorov-Smirnov test (the 19 | * Kuiper form is chosen because of its relative simplicity and because 20 | * it manages the tails of the interval symmetrically). However, 21 | * this is where alternative tests can also be applied if/when it is 22 | * determined necessary and an appropriate control structure is built 23 | * to permit their selection. Possibilities for tests include binning the 24 | * p-values and applying a discrete (Pearson chisq) analysis to determine 25 | * an overall p value (possibly accompanied by plotting of the binned 26 | * histogram of p-values for visual validation), using a confidence 27 | * interval test, using other KS tests (the ordinary KS test, the 28 | * Anderson-Darling KS test). 29 | * 30 | * However, it is to be expected that >>none of this will matter<< in 31 | * assessing the quality of an rng. The issue of robustness and 32 | * sensitivity come into play here. For each test, it should be 33 | * simple to find a region of test parameters (e.g. number of random 34 | * numbers tested per test) that makes a weak generator fail 35 | * unambiguously and consistently, generating an aggregate p-value of 36 | * 0.0000 (zero to four decimals) from any sensible assessment tool 37 | * that generates a p-value. 38 | *======================================================================== 39 | */ 40 | 41 | #include 42 | 43 | double sample(void *testfunc()) 44 | { 45 | 46 | int p; 47 | double pks; 48 | 49 | if(verbose == D_SAMPLE || verbose == D_ALL){ 50 | printf("# samples(): sample\n"); 51 | } 52 | for(p=0;p 37 | 38 | int rgb_kstest_test(Test **test, int irun) 39 | { 40 | 41 | uint t,tsamples; 42 | double *testvec; 43 | 44 | tsamples = test[0]->tsamples; 45 | testvec = (double *)malloc(tsamples*sizeof(double)); 46 | 47 | if(verbose == D_RGB_KSTEST_TEST || verbose == D_ALL){ 48 | printf("Generating a vector of %u uniform deviates.\n",test[0]->tsamples); 49 | } 50 | for(t=0;t= 3){ 62 | /* 63 | * This (Kuiper) can be selected with -k 3 from the command line. 64 | * All other values test variants of the regular kstest(). 65 | */ 66 | test[0]->pvalues[irun] = kstest_kuiper(testvec,tsamples); 67 | } else { 68 | /* 69 | * This (Symmetrized KS) is -k 0,1,2. Default is 0. 70 | */ 71 | test[0]->pvalues[irun] = kstest(testvec,tsamples); 72 | } 73 | 74 | free(testvec); 75 | 76 | if(verbose == D_RGB_KSTEST_TEST || verbose == D_ALL){ 77 | printf("# rgb_kstest_test(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 78 | } 79 | 80 | /* 81 | * I guess we return 0 on normal healthy return 82 | */ 83 | return(0); 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /libdieharder/histogram.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: histogram.c 529 2011-04-01 17:49:31Z rgbatduke $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * 6 | */ 7 | 8 | /* 9 | *======================================================================== 10 | * This code displays an ascii "*" histogram of the input e.g. p-value 11 | * vector. 12 | *======================================================================== 13 | */ 14 | 15 | 16 | #include 17 | 18 | 19 | void histogram(double *input,char *pvlabel,int inum,double min,double max,int nbins,char *label) 20 | { 21 | 22 | int i,j,hindex; 23 | uint *bin,binmax; 24 | double binscale; 25 | uint vscale; 26 | 27 | /* 28 | * This is where we put the binned count(s). Make and zero it 29 | */ 30 | bin = (uint *)malloc(nbins*sizeof(uint)); 31 | for(i=0;i= 20*vscale) { 70 | vscale++; 71 | /* printf("binmax = %u vscale = %u\n",binmax,vscale); */ 72 | } 73 | 74 | /* 75 | * Now we just display the histogram, which should be in range to 76 | * be displayed. 77 | */ 78 | for(i=20;i>0;i--){ 79 | if(i%2 == 0){ 80 | printf("# %5d|",i*vscale); 81 | } else { 82 | printf("# |"); 83 | } 84 | for(j=0;j= i*vscale ){ 86 | printf("****|"); 87 | } else { 88 | printf(" |"); 89 | } 90 | } 91 | printf("\n"); 92 | } 93 | printf("# |--------------------------------------------------\n"); 94 | printf("# |"); 95 | for(i=0;i 24 | 25 | #define POINTS_3D 4000 26 | #define DIM_3D 3 27 | 28 | typedef struct { 29 | double x[DIM_3D]; 30 | } C3_3D; 31 | 32 | int diehard_3dsphere(Test **test, int irun) 33 | { 34 | 35 | int j,k; 36 | C3_3D *c3; 37 | double r1,r2,r3,rmin,r3min; 38 | double xdelta,ydelta,zdelta; 39 | 40 | /* 41 | * for display only. Test dimension is 3, of course. 42 | */ 43 | test[0]->ntuple = 3; 44 | 45 | r3min = 0; 46 | 47 | /* 48 | * This one should be pretty straightforward. Generate a vector 49 | * of three random coordinates in the range 0-1000 (check the 50 | * diehard code to see what "in" a 1000^3 cube means, but I'm assuming 51 | * real number coordinates greater than 0 and less than 1000). Do 52 | * a simple double loop through to float the smallest separation out. 53 | * Generate p, save in a sample vector. Apply KS test. 54 | */ 55 | c3 = (C3_3D *)malloc(POINTS_3D*sizeof(C3_3D)); 56 | 57 | rmin = 2000.0; 58 | for(j=0;j=0;k--){ 72 | xdelta = c3[j].x[0]-c3[k].x[0]; 73 | ydelta = c3[j].x[1]-c3[k].x[1]; 74 | zdelta = c3[j].x[2]-c3[k].x[2]; 75 | r2 = xdelta*xdelta + ydelta*ydelta + zdelta*zdelta; 76 | r1 = sqrt(r2); 77 | r3 = r2*r1; 78 | if(verbose == D_DIEHARD_3DSPHERE || verbose == D_ALL){ 79 | printf("%d-%d: |(%6.2f,%6.2f,%6.2f)| = r1 = %f rmin = %f, \n", 80 | j,k,xdelta,ydelta,zdelta,r1,rmin); 81 | } 82 | if(r1pvalues[irun] = 1.0 - exp(-r3min/30.0); 93 | 94 | MYDEBUG(D_DIEHARD_3DSPHERE) { 95 | printf("# diehard_3dsphere(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 96 | } 97 | 98 | nullfree(c3); 99 | 100 | return(0); 101 | 102 | } 103 | 104 | -------------------------------------------------------------------------------- /libdieharder/dab_monobit2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ======================================================================== 3 | * $Id: sts_monobit.c 237 2006-08-23 01:33:46Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | * See also accompanying file STS.COPYING 7 | * ======================================================================== 8 | */ 9 | 10 | /* 11 | * ======================================================================== 12 | * Block-monobit test. 13 | * Since we don't know what block size to use, try a bunch of block sizes. 14 | * In particular, try all blocks sizes of 2^k words, where k={0..n}. 15 | * Not sure what n should be. Especially considering the difficulty with 16 | * getting a statistic out of the test. 17 | * ======================================================================== 18 | */ 19 | 20 | #include 21 | #define BLOCK_MAX (16) 22 | 23 | /* The evalMostExtreme function is in dab_dct.c */ 24 | extern double evalMostExtreme(double *pvalue, uint num); 25 | 26 | int dab_monobit2(Test **test, int irun) 27 | { 28 | uint i, j; 29 | uint blens = rmax_bits; 30 | uint ntup = ntuple; 31 | double *counts; 32 | uint *tempCount; 33 | double pvalues[BLOCK_MAX]; 34 | 35 | /* First, find out the maximum block size to use. 36 | * The maximum size will be 2^ntup words. 37 | */ 38 | if (ntup == 0) { 39 | for (j=0;jtsamples / (2<= BLOCK_MAX) { 46 | fprintf(stderr,"Error: Can only use ntup up to %i.\n", BLOCK_MAX-1); 47 | fprintf(stderr," Read test description with dieharder -d 209 -h.\n"); 48 | exit(0); 49 | } 50 | 51 | test[0]->ntuple = ntup; 52 | 53 | counts = (double *) malloc(sizeof(*counts) * blens * (2<tsamples;i++) { 60 | uint n = gsl_rng_get(rng); 61 | uint t = 1; 62 | 63 | // Begin: count bits 64 | n -= (n >> 1) & 0x55555555; 65 | n = (n & 0x33333333) + ((n >> 2) & 0x33333333); 66 | n = (n + (n >> 4)) & 0x0f0f0f0f; 67 | 68 | if (0) { 69 | n = (n * 0x01010101) >> 24; 70 | } else { 71 | n = n + (n >> 8); 72 | n = (n + (n >> 16)) & 0x3f; 73 | } 74 | // End: count bits 75 | 76 | for (j = 0; j < ntup; j++) { 77 | tempCount[j] += n; // Update block count 78 | 79 | if ((t & i) && !(t & (i-1))) { // If this is the start of a new block 80 | counts[blens * ((2<tsamples / (2<pvalues[irun] = evalMostExtreme(pvalues, ntup); 98 | 99 | nullfree(counts); 100 | nullfree(tempCount); 101 | 102 | return(0); 103 | } 104 | 105 | -------------------------------------------------------------------------------- /libdieharder/dab_bytedistrib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * See copyright in copyright.h and the accompanying file COPYING 3 | */ 4 | 5 | /* 6 | *======================================================================== 7 | * DAB Byte Distribution Test 8 | * 9 | * Extract n independent bytes from each of k consecutive words. Increment 10 | * indexed counters in each of n tables. (Total of 256 * n counters.) 11 | * Currently, n=3 and is fixed at compile time. 12 | * If n>=2, then the lowest and highest bytes will be used, along 13 | * with n-2 bytes from the middle. 14 | * If the generator's word size is too small, overlapped bytes will 15 | * be used. 16 | * Current, k=3 and is fixed at compile time. 17 | * Use a basic chisq fitting test (chisq_pearson) for the p-value. 18 | * Previous version also used a chisq independence test (chisq2d); it 19 | * was found to be slightly less sensitive. 20 | * I envisioned this test as using a small number of samples and large 21 | * number of separate tests. Experiments so far show that keeping -p 1 22 | * and increasing -t performs best. 23 | *======================================================================== 24 | */ 25 | 26 | #include 27 | 28 | 29 | #define SAMP_PER_WORD 3 30 | #define SAMP_TOTAL (3*SAMP_PER_WORD) 31 | #define TABLE_SIZE (256 * SAMP_TOTAL) 32 | 33 | int dab_bytedistrib(Test **test,int irun) { 34 | Vtest vtest; 35 | unsigned int t,i,j; 36 | unsigned int counts[TABLE_SIZE]; 37 | 38 | /* Zero the counters */ 39 | memset(counts, 0, sizeof(unsigned int) * TABLE_SIZE); 40 | 41 | test[0]->ntuple = 0; // Not used currently 42 | 43 | for(t=0;ttsamples;t++){ 44 | for(i=0;i<(SAMP_TOTAL / SAMP_PER_WORD);i++){ 45 | 46 | /* 47 | * Generate a word; this word will be used for SAMP_PER_WORD bytes. 48 | */ 49 | unsigned int word = gsl_rng_get(rng); 50 | unsigned char currentShift = 0; 51 | for (j = 0; j < SAMP_PER_WORD; j++) { 52 | 53 | /* 54 | * Shifts: 55 | * The "shiftAmount" is how much the word needs to be shifted for the 56 | * *next* byte, since the current byte is read before shifting. 57 | * The calculation is such that the final byte read is always the most 58 | * significant byte. The middle bytes fall as they will. 59 | * The calculation is uglier than I wanted, but it handles fractional 60 | * shift amounts correctly (at least I think it does; confirmed for 61 | * SAMP_PER_WORD==3 and a variety of rmax_bits values). 62 | */ 63 | unsigned char shiftAmount = ((j+1) * (rmax_bits - 8)) / (SAMP_PER_WORD - 1); 64 | unsigned int v = word & 0x0ff; /* v is the byte sampled from the word */ 65 | word >>= shiftAmount - currentShift; 66 | currentShift += shiftAmount; 67 | 68 | /* 69 | * Increment the appropriate count, faking a 3d array using a 1d array. 70 | * This should probably be changed, so that v is the final index and 71 | * not j, for clarity. 72 | */ 73 | counts[v * SAMP_TOTAL + i * SAMP_PER_WORD + j]++; 74 | } 75 | } 76 | } 77 | 78 | Vtest_create(&vtest, TABLE_SIZE); 79 | vtest.ndof = 255 * SAMP_TOTAL; 80 | 81 | /* 82 | * Setup the chisq test, setting the actual and expected values for 83 | * each entry. 84 | */ 85 | for(i=0;itsamples / 256; 88 | } 89 | 90 | Vtest_eval(&vtest); 91 | test[0]->pvalues[irun] = vtest.pvalue; 92 | Vtest_destroy(&vtest); 93 | 94 | return(0); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /include/dieharder/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * $Id: libdieharder.h 221 2006-08-16 22:43:03Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | *======================================================================== 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | //#include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | /* 46 | #include 47 | #include 48 | */ 49 | 50 | /* Diehard Tests (by number) */ 51 | typedef enum { 52 | DIEHARD_NONE, 53 | DIEHARD_BDAY, 54 | DIEHARD_OPERM5, 55 | DIEHARD_RANK_32x32, 56 | DIEHARD_RANK_6x8, 57 | DIEHARD_BITSTREAM, 58 | DIEHARD_OPSO, 59 | DIEHARD_OQSO, 60 | DIEHARD_DNA, 61 | DIEHARD_COUNT_1S_STREAM, 62 | DIEHARD_COUNT_1S_BYTE, 63 | DIEHARD_PARKING_LOT, 64 | DIEHARD_2DSPHERE, 65 | DIEHARD_3DSPHERE, 66 | DIEHARD_SQUEEZE, 67 | DIEHARD_SUMS, 68 | DIEHARD_RUNS, 69 | DIEHARD_CRAPS, 70 | MARSAGLIA_TSANG_GCD, 71 | MARSAGLIA_TSANG_GORILLA, 72 | N_DIEHARD_TESTS 73 | } Diehard_Tests; 74 | 75 | /* RGB Tests (by number) */ 76 | typedef enum { 77 | RGB_NONE, 78 | RGB_TIMING, 79 | RGB_PERSIST, 80 | RGB_BITDIST, 81 | RGB_MINIMUM_DISTANCE, 82 | RGB_PERMUTATIONS, 83 | RGB_LAGGED_SUMS, 84 | RGB_LMN, 85 | //RGB_OPERM, 86 | DAB_BIRTHDAYS1, 87 | DAB_BYTEDISTRIB, 88 | DAB_DCT, 89 | DAB_FILLTREE, 90 | DAB_FILLTREE2, 91 | DAB_MONOBIT2, 92 | DAB_OPSO2, 93 | N_RGB_TESTS 94 | } Rgb_Tests; 95 | 96 | typedef enum { 97 | STS_NONE, 98 | STS_MONOBIT, 99 | STS_RUNS, 100 | STS_SERIAL, 101 | N_STS_TESTS 102 | } Sts_Tests; 103 | 104 | /* 105 | * Add your own test types here! Use/rename/copy template here and in 106 | * the subroutine prototypes below. Note also the D_USER_TEMPLATE in 107 | * the Debug enum, in case you want to add controllable I/O to help 108 | * you debug with the -v flag. 109 | */ 110 | typedef enum { 111 | USER_NONE, 112 | USER_TEMPLATE, 113 | N_USER_TESTS 114 | } User_Tests; 115 | 116 | 117 | -------------------------------------------------------------------------------- /libdieharder/sts_runs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: sts_runs.c 237 2006-08-23 01:33:46Z rgb $ 3 | * 4 | * See copyright in copyright.h and the accompanying file COPYING 5 | * See also accompanying file STS.COPYING 6 | * 7 | */ 8 | 9 | /* 10 | *======================================================================== 11 | * This is a the monobit test, rewritten from the description in the 12 | * STS suite. 13 | * 14 | * Rewriting means that I can standardize the interface to gsl-encapsulated 15 | * routines more easily. It also makes this my own code. 16 | *======================================================================== 17 | */ 18 | 19 | #include 20 | 21 | int sts_runs(Test **test, int irun) 22 | { 23 | 24 | int b,t; 25 | uint value; 26 | uint *rand_int; 27 | Xtest ptest; 28 | double pones,c00,c01,c10,c11;; 29 | 30 | /* 31 | * for display only. 2 means sts_runs tests 2-tuples. 32 | */ 33 | test[0]->ntuple = 2; 34 | 35 | /* 36 | * Allocate the space needed by the test. 37 | */ 38 | rand_int = (uint *)malloc(test[0]->tsamples*sizeof(uint)); 39 | 40 | /* 41 | * Number of total bits from -t test[0]->tsamples = size of rand_int[] 42 | */ 43 | bits = rmax_bits*test[0]->tsamples; 44 | 45 | /* 46 | * We have to initialize these a bit differently this time 47 | */ 48 | ptest.x = 0.0; 49 | 50 | /* 51 | * Create entire bitstring to be tested 52 | */ 53 | for(t=0;ttsamples;t++){ 54 | rand_int[t] = gsl_rng_get(rng); 55 | } 56 | 57 | /* 58 | * Fill vector of "random" integers with selected generator. 59 | * NOTE WELL: This can also be done by reading in a file! 60 | */ 61 | pones = 0.0; 62 | c00 = 0.0; 63 | c01 = 0.0; 64 | c10 = 0.0; /* Equal to c01 by obvious periodic symmetry */ 65 | c11 = 0.0; 66 | for(b=0;btsamples,2,b); 72 | switch(value){ 73 | case 0: /* 00 no new ones */ 74 | c00++; 75 | break; 76 | case 1: /* 01 no new ones */ 77 | c01++; 78 | ptest.x++; 79 | break; 80 | case 2: /* 10 one new one (from the left) */ 81 | c10++; 82 | ptest.x++; 83 | pones++; 84 | break; 85 | case 3: /* 11 one new one (from the left) */ 86 | c11++; 87 | pones++; 88 | break; 89 | } 90 | MYDEBUG(D_STS_RUNS) { 91 | printf("# sts_runs(): ptest.x = %f, pone = %f\n",ptest.x,pones); 92 | } 93 | } 94 | /* 95 | * form the probability of getting a one in the entire sample 96 | */ 97 | pones /= (double) test[0]->tsamples*rmax_bits; 98 | c00 /= (double) test[0]->tsamples*rmax_bits; 99 | c01 /= (double) test[0]->tsamples*rmax_bits; 100 | c10 /= (double) test[0]->tsamples*rmax_bits; 101 | c11 /= (double) test[0]->tsamples*rmax_bits; 102 | 103 | /* 104 | * Now we can finally compute the targets for the problem. 105 | */ 106 | ptest.y = 2.0*bits*pones*(1.0-pones); 107 | ptest.sigma = 2.0*sqrt(bits)*pones*(1.0-pones); 108 | 109 | MYDEBUG(D_STS_RUNS) { 110 | printf(" p = %f c00 = %f c01 = %f c10 = %f c11 = %f\n",pones,c00,c01,c10,c11); 111 | } 112 | 113 | Xtest_eval(&ptest); 114 | test[0]->pvalues[irun] = ptest.pvalue; 115 | 116 | MYDEBUG(D_STS_RUNS) { 117 | printf("# sts_runs(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 118 | } 119 | 120 | free(rand_int); 121 | 122 | return(0); 123 | 124 | } 125 | 126 | -------------------------------------------------------------------------------- /dieharder/set_globals.c: -------------------------------------------------------------------------------- 1 | /* 2 | * See copyright in copyright.h and the accompanying file COPYING 3 | */ 4 | 5 | #include "dieharder.h" 6 | 7 | void set_globals() 8 | { 9 | 10 | /* 11 | * Within reason, the following user-controllable options are referenced 12 | * by a flag with the same first letter. In order: 13 | */ 14 | all = NO; /* Default is to NOT do all the tests */ 15 | dtest_num = -1; /* -1 means no test selected */ 16 | dtest_name[0] = (char)0; /* empty test name is also default */ 17 | filename[0] = (char)0; /* No input file */ 18 | fromfile = 0; /* Not from an input file */ 19 | ks_test = 0; /* Default is 0, Symmetrized KS test */ 20 | output_file = 0; /* No output file */ 21 | output_format = 1; /* uint output format if you use -o alone */ 22 | /* Cruft overlap = 1; / * Default is to use overlapping samples */ 23 | multiply_p = 1; /* Default is to use default number of psamples */ 24 | gnumbs[0] = 13; /* Default is mt19937 as a "good" generator */ 25 | generator_name[0] = (char)0; /* empty generator name is default */ 26 | gvcount = 0; /* Count of generators so far */ 27 | gscount = 0; /* Count of seeds so far */ 28 | help_flag = NO; /* No help requested */ 29 | iterations = -1; /* For timing loop, set iterations to be timed */ 30 | list = NO; /* List all generators */ 31 | ntuple = 0; /* n-tuple size for n-tuple tests (0 means all) */ 32 | overlap = 1; /* Default is to use overlapping samples in tests that support a choice */ 33 | psamples = 0; /* This value precipitates use of test defaults */ 34 | seed = 0; /* saves the current (possibly randomly selected) seed */ 35 | strategy = 0; /* Means use seed (random or otherwise) from beginning of run */ 36 | Seed = 0; /* user selected seed. != 0 surpresses reseeding per sample.*/ 37 | tsamples = 0; /* This value precipitates use of test defaults */ 38 | table_separator = '|'; /* Default table separator is | for human readability */ 39 | /* 40 | * Table flags to turn on all of these outputs are defined in output.h, 41 | * and can also be added by name or number on the command line as in: 42 | * -T seed -T pvalues 43 | */ 44 | tflag_default = THEADER + TSHOW_RNG + TLINE_HEADER + TTEST_NAME + TNTUPLE + 45 | TPSAMPLES + TTSAMPLES + TPVALUES + TASSESSMENT + TRATE + 46 | TSEED; 47 | tflag = 0; /* We START with this zero so we can accumulate */ 48 | verbose = 0; /* Default is not to be verbose. */ 49 | /* 50 | * These are controls for Test To Destruction (TTD) and Resolve Ambiguity 51 | * (RA) modes (as well as normal test reporting). They arguably should 52 | * not be globals, as they all are used only in the UI. I'm going to 53 | * leave them in libdieharder.h for the moment, though, until all of 54 | * these changes settle down because they ARE likely to be used by any UI 55 | * that seeks to implement similar search strategy control. 56 | */ 57 | Xtrategy = 0; /* 0 means "no strategy, off", the default */ 58 | Xweak = 0.005; /* Point where generator is flagged as "weak" */ 59 | Xfail = 0.000001; /* Point where generator unambiguously fails dieharder */ 60 | Xstep = 100; /* Number of pvalues to add when iterating in TTD/RA */ 61 | Xoff = 100000; /* This is quite stressful and may run a long time */ 62 | x_user = 0.0; /* x,y,z_user are for "arbitrary" input controls */ 63 | y_user = 0.0; /* and can be used by any test without having to */ 64 | z_user = 0.0; /* rewrite parsecl() or add global variables */ 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /libdieharder/rng_kiss.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rng_kiss.c 3 | * 4 | * This is a version of (j)kiss (in C) from: 5 | * 6 | * Good Practice in (Pseudo) Random Number Generation for 7 | * Bioinformatics Applications 8 | * 9 | * http://www.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf 10 | * 11 | * David Jones, UCL Bioinformatics Group 12 | * (E-mail: d.jones@cs.ucl.ac.uk) 13 | * (Last revised May 7th 2010) 14 | * 15 | * GSL packaged for dieharder by Robert G. Brown 01/06/11 16 | * 17 | * David has kindly agreed to make this code vailable under the GPL so 18 | * it can be integrated with the dieharder package and/or the Gnu 19 | * Scentific Libraary (GSL). 20 | * 21 | */ 22 | 23 | #include 24 | 25 | static unsigned long int kiss_get (void *vstate); 26 | static double kiss_get_double (void *vstate); 27 | static void kiss_set (void *vstate, unsigned long int s); 28 | 29 | typedef struct { 30 | /* 31 | * Seed variables. Note that kiss requires a moderately complex 32 | * seeding using a "seed rng" that we will arbitrarily set to be 33 | * a MT from the GSL. This makes this routine NOT PORTABLE, but 34 | * D. Jones' article (URL above) contains a portable, public doman 35 | * version of this code that includes a seeding routine (and commentary!). 36 | */ 37 | unsigned int x; 38 | unsigned int y; 39 | unsigned int z; 40 | unsigned int c; 41 | } kiss_state_t; 42 | 43 | 44 | static unsigned long int kiss_get (void *vstate) 45 | { 46 | 47 | kiss_state_t *state = vstate; 48 | unsigned long long t; 49 | state->x = 314527869 * state->x + 1234567; 50 | state->y ^= state->y << 5; 51 | state->y ^= state->y >> 7; 52 | state->y ^= state->y << 22; 53 | t = 4294584393ULL * state->z + state->c; 54 | state->c = t >> 32; 55 | state->z = t; 56 | return (unsigned int)(state->x + state->y + state->z); 57 | 58 | } 59 | 60 | static double kiss_get_double (void *vstate) 61 | { 62 | return (double) kiss_get (vstate) / (double) UINT_MAX; 63 | } 64 | 65 | static void 66 | kiss_set (void *vstate, unsigned long int s) 67 | { 68 | 69 | /* Initialize automaton using specified seed. */ 70 | kiss_state_t *state = (kiss_state_t *) vstate; 71 | 72 | uint seed_seed; 73 | gsl_rng *seed_rng; /* random number generator used to seed uvag */ 74 | 75 | /* 76 | * kiss needs four random number seeds. They have to be reproducible 77 | * from a single seed in order to be consistent with the GSL. We 78 | * therefore have to do a two step process where we use seed to 79 | * seed an existing GSL generator (say mt19937_1999) and take the 80 | * first three returns as the rest of our seed for this generator. 81 | */ 82 | seed_rng = gsl_rng_alloc(dh_rng_types[14]); 83 | seed_seed = s; 84 | gsl_rng_set(seed_rng,seed_seed); 85 | /* printf("Seeding kiss\n"); */ 86 | state->x = gsl_rng_get(seed_rng); 87 | while (!(state->y = gsl_rng_get(seed_rng))); /* y must not be zero! */ 88 | state->z = gsl_rng_get(seed_rng); 89 | /* printf("Done!\n"); */ 90 | 91 | /* 92 | * We don't really need to set c as well but let's anyway. 93 | * Notes: offset c by 1 to avoid z=c=0; should be less than 698769069. 94 | */ 95 | state->c = gsl_rng_get(seed_rng) % 698769068 + 1; 96 | /* printf("x = %10u y = %10u z = %10u c = %10u\n", 97 | state->x,state->y,state->z,state->c); */ 98 | return; 99 | 100 | } 101 | 102 | static const gsl_rng_type kiss_type = 103 | {"kiss", /* name */ 104 | UINT_MAX, /* RAND_MAX */ 105 | 0, /* RAND_MIN */ 106 | sizeof (kiss_state_t), 107 | &kiss_set, 108 | &kiss_get, 109 | &kiss_get_double}; 110 | 111 | const gsl_rng_type *gsl_rng_kiss = &kiss_type; 112 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_DLFCN_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_INTTYPES_H 11 | 12 | /* Define to 1 if you have the `gsl' library (-lgsl). */ 13 | #undef HAVE_LIBGSL 14 | 15 | /* Define to 1 if you have the `gslcblas' library (-lgslcblas). */ 16 | #undef HAVE_LIBGSLCBLAS 17 | 18 | /* Define to 1 if you have the `m' library (-lm). */ 19 | #undef HAVE_LIBM 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STDINT_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STDIO_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_STDLIB_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_STRINGS_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_STRING_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_SYS_STAT_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_SYS_TIME_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_SYS_TYPES_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_UNISTD_H 47 | 48 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 49 | #undef LT_OBJDIR 50 | 51 | /* Name of package */ 52 | #undef PACKAGE 53 | 54 | /* Define to the address where bug reports for this package should be sent. */ 55 | #undef PACKAGE_BUGREPORT 56 | 57 | /* Define to the full name of this package. */ 58 | #undef PACKAGE_NAME 59 | 60 | /* Define to the full name and version of this package. */ 61 | #undef PACKAGE_STRING 62 | 63 | /* Define to the one symbol short name of this package. */ 64 | #undef PACKAGE_TARNAME 65 | 66 | /* Define to the home page for this package. */ 67 | #undef PACKAGE_URL 68 | 69 | /* Define to the version of this package. */ 70 | #undef PACKAGE_VERSION 71 | 72 | /* Description */ 73 | #undef RELEASED 74 | 75 | /* Define to 1 if all of the C90 standard headers exist (not just the ones 76 | required in a freestanding environment). This macro is provided for 77 | backward compatibility; new code need not use it. */ 78 | #undef STDC_HEADERS 79 | 80 | /* Define to 1 if you can safely include both and . This 81 | macro is obsolete. */ 82 | #undef TIME_WITH_SYS_TIME 83 | 84 | /* Version number of package */ 85 | #undef VERSION 86 | 87 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 88 | significant byte first (like Motorola and SPARC, unlike Intel). */ 89 | #if defined AC_APPLE_UNIVERSAL_BUILD 90 | # if defined __BIG_ENDIAN__ 91 | # define WORDS_BIGENDIAN 1 92 | # endif 93 | #else 94 | # ifndef WORDS_BIGENDIAN 95 | # undef WORDS_BIGENDIAN 96 | # endif 97 | #endif 98 | 99 | /* Define to empty if `const' does not conform to ANSI C. */ 100 | #undef const 101 | 102 | /* Define to `__inline__' or `__inline' if that's what the C compiler 103 | calls it, or to nothing if 'inline' is not supported under any name. */ 104 | #ifndef __cplusplus 105 | #undef inline 106 | #endif 107 | 108 | /* Define to `unsigned int' if does not define. */ 109 | #undef size_t 110 | 111 | /* Define to empty if the keyword `volatile' does not work. Warning: valid 112 | code using `volatile' can become incorrect without. Disable with care. */ 113 | #undef volatile 114 | -------------------------------------------------------------------------------- /libdieharder/rgb_lagged_sums.c: -------------------------------------------------------------------------------- 1 | /* 2 | * See copyright in copyright.h and the accompanying file COPYING 3 | */ 4 | 5 | /* 6 | *======================================================================== 7 | * RGB Lagged Sums Test 8 | * 9 | * This is a very simple test template for a test that generates a single 10 | * trivial statistic -- in fact, it is the demo user test from the 11 | * dieharder CLI sources. Use a GSL-wrapped generator to generate the 12 | * rands required to sample that number, obtaining an iid (independent, 13 | * identically distributed) set of samples. find their mean. Determine 14 | * the probability of obtaining that particular value by a random trial 15 | * (from the erf of the associated normal distribution) -- this is the 16 | * "p-value" of the trial. 17 | * 18 | * The interesting thing about this test is that -- simple as it is -- when 19 | * it is run on an rng for a series of possible lags, it suffices to show 20 | * that e.g. mt19937 is actually weak because it is TOO UNIFORM -- the set 21 | * of pvalues that result from performing the lagged sum test for certain 22 | * lags come out too uniformly distributed between 0 and 1 so that the 23 | * final KS test yields a pvalue of e.g. 0.9995... -- a two in ten thousand 24 | * chance -- for two or three lags in the range 0-32. Similar weakness is 25 | * actually observed for rgb_permutations. This might not affect most 26 | * simulations based on the generator -- many of them would if anything 27 | * benefit from a slight "over-uniformity" of the random number stream, 28 | * especially when it is only apparent for certain lags and seeds. Others 29 | * might fail altogether because certain tails in the space of random 30 | * numbers aren't being sampled at the expected rate. It is very much 31 | * caveat emptor for users of pseudo-random number generators as all of them 32 | * are likely weak SOMEWHERE -- dieharder just gives you a microscope to use 33 | * to reveal their specific weaknesses and the likely bounds where they 34 | * won't matter. 35 | *======================================================================== 36 | */ 37 | 38 | #include 39 | 40 | int rgb_lagged_sums(Test **test,int irun) 41 | { 42 | 43 | uint t,i,lag; 44 | Xtest ptest; 45 | 46 | /* 47 | * Get the lag from ntuple. Note that a lag of zero means 48 | * "don't throw any away". 49 | */ 50 | test[0]->ntuple = ntuple; 51 | lag = test[0]->ntuple; 52 | 53 | /* 54 | * ptest.x = actual sum of tsamples lagged samples from rng 55 | * ptest.y = tsamples*0.5 is the expected mean value of the sum 56 | * ptest.sigma = sqrt(tsamples/12.0) is the standard deviation 57 | */ 58 | ptest.x = 0.0; /* Initial value */ 59 | ptest.y = (double) test[0]->tsamples*0.5; 60 | ptest.sigma = sqrt(test[0]->tsamples/12.0); 61 | 62 | if(verbose == D_RGB_LAGGED_SUMS || verbose == D_ALL){ 63 | printf("# rgb_lagged_sums(): Doing a test with lag %u\n",lag); 64 | } 65 | 66 | for(t=0;ttsamples;t++){ 67 | 68 | /* 69 | * A VERY SIMPLE test, but sufficient to demonstrate the 70 | * weaknesses in e.g. mt19937. 71 | */ 72 | 73 | /* Throw away lag per sample */ 74 | for(i=0;ipvalues[irun] = ptest.pvalue; 83 | 84 | if(verbose == D_RGB_LAGGED_SUMS || verbose == D_ALL){ 85 | printf("# rgb_lagged_sums(): ks_pvalue[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 86 | } 87 | 88 | return(0); 89 | 90 | } 91 | 92 | void help_rgb_lagged_sums() 93 | { 94 | 95 | printf("%s",rgb_lagged_sums_dtest.description); 96 | 97 | } 98 | -------------------------------------------------------------------------------- /libdieharder/bauer/rng_threefish.c: -------------------------------------------------------------------------------- 1 | /* rng_threefish 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include 21 | #include "skein.h" 22 | 23 | // State blocks = 1 for weakest form 24 | #define STATE_BLOCKS (1) 25 | #define BLOCKS_SIZE (64 * STATE_BLOCKS) 26 | 27 | #define Threefish_512_Process_Blocks(a,b,c,d) Threefish_512_Process_Blocks64(a,b,c,d) 28 | 29 | /* 30 | * This is a wrapping of the Threefish algorithm as a generator 31 | */ 32 | 33 | typedef struct { 34 | Threefish_512_Ctxt_t ctx; 35 | unsigned char block[BLOCKS_SIZE]; 36 | short int pos; 37 | } Threefish_state_t; 38 | 39 | unsigned long int threefish_get (void *vstate); 40 | double threefish_get_double (void *vstate); 41 | void threefish_set (void *vstate, unsigned long int s); 42 | 43 | #ifndef BADRNG 44 | unsigned long int threefish_get_long (void *vstate) { 45 | Threefish_state_t *state = vstate; 46 | unsigned long int ret; 47 | 48 | if (state->pos + sizeof(unsigned long int) > BLOCKS_SIZE) { 49 | Threefish_512_Process_Blocks(&(state->ctx), state->block, state->block, STATE_BLOCKS); 50 | state->pos = 0; 51 | } 52 | 53 | ret = *((unsigned long int *) (state->block + state->pos)); 54 | state->pos += sizeof(unsigned long int); 55 | 56 | return(ret); 57 | } 58 | 59 | unsigned long int threefish_get (void *vstate) { 60 | Threefish_state_t *state = vstate; 61 | unsigned int ret; 62 | 63 | if (state->pos + sizeof(ret) > BLOCKS_SIZE) { 64 | Threefish_512_Process_Blocks(&(state->ctx), state->block, state->block, STATE_BLOCKS); 65 | state->pos = 0; 66 | } 67 | 68 | ret = *((unsigned int *) (state->block + state->pos)); 69 | state->pos += sizeof(ret); 70 | 71 | // ret &= 0x7fffffff; 72 | return(ret); 73 | } 74 | 75 | 76 | double threefish_get_double (void *vstate) { 77 | // return threefish_get_long(vstate) / (double) ULONG_MAX; 78 | return (double) threefish_get(vstate) / (double) (UINT_MAX >> 0); 79 | } 80 | 81 | void threefish_set (void *vstate, unsigned long int s) { 82 | Threefish_state_t *state = vstate; 83 | int i; 84 | 85 | memset(state, 0, sizeof(*state)); 86 | for (i = 0; i < 16; i++) ((unsigned char *) state->ctx.T)[i] = 112 + i; 87 | for (i = 0; i < 64; i++) ((unsigned char *) state->ctx.Key)[i] = 64 + i; 88 | *((unsigned long int *) state->block) = s; 89 | Threefish_512_Process_Blocks(&(state->ctx), state->block, state->block, 1); 90 | 91 | for (i = 1; i < STATE_BLOCKS; i++) { 92 | state->ctx.T[0] = i; 93 | Threefish_512_Process_Blocks(&(state->ctx), state->block, state->block+(i*64), 1); 94 | } 95 | state->ctx.T[0] = 112; 96 | 97 | return; 98 | } 99 | 100 | static const gsl_rng_type threefish_type = { 101 | "Threefish_OFB", /* name */ 102 | UINT_MAX>>0, // UINT_MAX, /* RAND_MAX */ 103 | 0, /* RAND_MIN */ 104 | sizeof (Threefish_state_t), 105 | &threefish_set, 106 | &threefish_get, 107 | &threefish_get_double}; 108 | 109 | const gsl_rng_type *gsl_rng_threefish = &threefish_type; 110 | #endif 111 | 112 | -------------------------------------------------------------------------------- /dieharder/list_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * See copyright in copyright.h and the accompanying file COPYING 4 | *======================================================================== 5 | */ 6 | 7 | /* 8 | * ======================================================================== 9 | * This routine simply lists all the tests currently known to dieharder. 10 | * VERY SOON NOW we will automate it and make it look EXACTLY like 11 | * the list_rngs() output. 12 | * ======================================================================== 13 | */ 14 | 15 | #include "dieharder.h" 16 | 17 | void list_tests() 18 | { 19 | 20 | int i; 21 | 22 | dieharder_test_types(); 23 | 24 | dh_header(); 25 | fprintf(stdout,"Installed dieharder tests:\n"); 26 | fprintf(stdout,"%12s\t%30s\t%30s\n","Test Number","Test Name","Test Reliability"); 27 | fprintf(stdout,"===============================================================================\n"); 28 | for(i=0;i<900;i++){ 29 | if(dh_test_types[i]){ 30 | fprintf(stdout," -d %d \t%40s",i,dh_test_types[i]->name); 31 | if( i == 5 || i == 6 || i == 7 ){ 32 | fprintf(stdout,"\t%10s\n","Suspect"); 33 | } else if(i == 14){ 34 | fprintf(stdout,"\t%10s\n","Do Not Use"); 35 | } else { 36 | fprintf(stdout,"\t%10s\n","Good"); 37 | } 38 | 39 | } 40 | 41 | } 42 | 43 | } 44 | 45 | void list_tests_old() 46 | { 47 | 48 | dh_header(); 49 | 50 | printf("\n\ 51 | Bug/Development Key (use at your own risk):\n\ 52 | rft = ready for testing (the test may - or may not - work correctly)\n\ 53 | sus = suspect test (consistently fails \"good\" generators)\n\ 54 | dev = development only (may crash, isn't finished)\n\ 55 | \n\ 56 | Only fully reliable tests will be run when diehard -a is invoked,\n\ 57 | with \"reasonable\" default parameters. \n\ 58 | \n\ 59 | PLEASE READ THE MAN PAGE to learn about p-values and the null hypothesis\n\ 60 | in testing BEFORE using this testing tool!\n\ 61 | \n\ 62 | Diehard Tests\n\ 63 | -d 1 Diehard Birthdays test\n\ 64 | [sus: -d 2 Diehard Overlapping Permutations test]\n\ 65 | -d 3 Diehard 32x32 Binary Rank test\n\ 66 | -d 4 Diehard 6x8 Binary Rank test\n\ 67 | -d 5 Diehard Bitstream test\n\ 68 | -d 6 Diehard OPSO test\n\ 69 | -d 7 Diehard OQSO test\n\ 70 | -d 8 Diehard DNA test\n\ 71 | -d 9 Diehard Count the 1s (stream) test\n\ 72 | -d 10 Diehard Count the 1s (byte) test\n\ 73 | -d 11 Diehard Parking Lot test\n\ 74 | -d 12 Diehard Minimum Distance (2D Spheres) test\n\ 75 | -d 13 Diehard 3D Spheres (minimum distance) test\n\ 76 | -d 14 Diehard Squeeze test\n\ 77 | [sus: -d 15 Diehard Sums test]\n\ 78 | -d 16 Diehard Runs test\n\ 79 | -d 17 Diehard Craps test\n\ 80 | -d 18 Marsaglia and Tsang GCD test\n\ 81 | [dev: -d 19 Marsaglia and Tsang Gorilla test]\n\ 82 | \n\ 83 | RGB Tests\n\ 84 | -r 1 RGB Timing test (times the rng)\n\ 85 | -r 2 RGB Bit Persistence test\n\ 86 | -r 3 RGB Ntuple Bit Distribution test suite (-n ntuple)\n\ 87 | -r 4 RGB Generalized Minimum Distance test\n\ 88 | -r 5 RGB Permutations test (new, partial replacement for operm tests)]\n\ 89 | [rft: -r 6 RGB Lagged Sums test\n\ 90 | (do not use the following as tests yet)\n\ 91 | [dev: -r 7 RGB L-M-Ntuple Distribution test suite (quite long)]\n\ 92 | [dev: -r 8 RGB Overlapping Permutations test]\n\ 93 | [rft: -r 9 RGB KStest test]\n\ 94 | \n\ 95 | Statistical Test Suite (STS)\n\ 96 | -s 1 STS Monobit test\n\ 97 | -s 2 STS Runs test\n\ 98 | -s 3 STS Serial test\n\ 99 | \n\ 100 | User Tests\n\ 101 | -u 1 User Template (Lagged Sum Test)\n\ 102 | \n"); 103 | 104 | } 105 | -------------------------------------------------------------------------------- /libdieharder/diehard_rank_6x8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ======================================================================== 3 | * $Id: diehard_birthdays.c 250 2006-10-10 05:02:26Z rgb $ 4 | * 5 | * See copyright in copyright.h and the accompanying file COPYING 6 | * ======================================================================== 7 | */ 8 | 9 | /* 10 | * ======================================================================== 11 | * This is the Diehard BINARY RANK 6x8 test, rewritten from the 12 | * description in tests.txt on George Marsaglia's diehard site. 13 | * 14 | * This is the BINARY RANK TEST for 6x8 matrices. From each of :: 15 | * six random 32-bit integers from the generator under test, a :: 16 | * specified byte is chosen, and the resulting six bytes form a :: 17 | * 6x8 binary matrix whose rank is determined. That rank can be :: 18 | * from 0 to 6, but ranks 0,1,2,3 are rare; their counts are :: 19 | * pooled with those for rank 4. Ranks are found for 100,000 :: 20 | * random matrices, and a chi-square test is performed on :: 21 | * counts for ranks 6,5 and <=4. :: 22 | * 23 | * =================================================================== 24 | */ 25 | 26 | #include 27 | 28 | /* 29 | * Include inline uint generator 30 | */ 31 | #include "static_get_bits.c" 32 | 33 | int diehard_rank_6x8(Test **test, int irun) 34 | { 35 | 36 | 37 | int i,t,rank; 38 | uint bitstring; 39 | uint **mtx; 40 | Vtest vtest; 41 | 42 | MYDEBUG(D_DIEHARD_RANK_6x8){ 43 | fprintf(stdout,"# diehard_rank_6x8(): Starting test.\n"); 44 | } 45 | 46 | /* 47 | * for display only. 0 means "ignored". 48 | */ 49 | test[0]->ntuple = 0; 50 | 51 | mtx = (uint **)malloc(6*sizeof(uint *)); 52 | for(i=0;i<6;i++){ 53 | mtx[i] = (uint *)malloc(8*sizeof(uint)); 54 | } 55 | 56 | Vtest_create(&vtest,7); 57 | vtest.cutoff = 5.0; 58 | for(i=0;i<2;i++){ 59 | vtest.x[0] = 0.0; 60 | vtest.y[0] = 0.0; 61 | } 62 | vtest.x[2] = 0.0; 63 | vtest.y[2] = test[0]->tsamples*0.149858E-06; 64 | vtest.x[3] = 0.0; 65 | vtest.y[3] = test[0]->tsamples*0.808926E-04; 66 | vtest.x[4] = 0.0; 67 | vtest.y[4] = test[0]->tsamples*0.936197E-02; 68 | vtest.x[5] = 0.0; 69 | vtest.y[5] = test[0]->tsamples*0.217439E+00; 70 | vtest.x[6] = 0.0; 71 | vtest.y[6] = test[0]->tsamples*0.773118E+00; 72 | 73 | for(t=0;ttsamples;t++){ 74 | 75 | /* 76 | * We generate 6 random rmax_bits-bit integers and put a 77 | * randomly chosen byte into the LEFTMOST byte position 78 | * of the row/slot of mtx. 79 | */ 80 | MYDEBUG(D_DIEHARD_RANK_6x8){ 81 | fprintf(stdout,"# diehard_rank_6x8(): Input random matrix = \n"); 82 | } 83 | for(i=0;i<6;i++){ 84 | MYDEBUG(D_DIEHARD_RANK_6x8){ 85 | fprintf(stdout,"# "); 86 | } 87 | 88 | bitstring = get_rand_bits_uint(32,0xffffffff,rng); 89 | mtx[i][0] = bitstring; 90 | 91 | MYDEBUG(D_DIEHARD_RANK_6x8){ 92 | dumpbits(mtx[i],32); 93 | fprintf(stdout,"\n"); 94 | } 95 | } 96 | 97 | rank = binary_rank(mtx,6,8); 98 | MYDEBUG(D_DIEHARD_RANK_6x8){ 99 | printf("binary rank = %d\n",rank); 100 | } 101 | 102 | if(rank <= 2){ 103 | vtest.x[2]++; 104 | } else { 105 | vtest.x[rank]++; 106 | } 107 | } 108 | 109 | /* for(i=0;i<33;i++) printf("vtest.x[%d] = %f\n",i,vtest.x[i]); */ 110 | 111 | Vtest_eval(&vtest); 112 | test[0]->pvalues[irun] = vtest.pvalue; 113 | MYDEBUG(D_DIEHARD_RANK_6x8) { 114 | printf("# diehard_rank_6x8(): test[0]->pvalues[%u] = %10.5f\n",irun,test[0]->pvalues[irun]); 115 | } 116 | 117 | Vtest_destroy(&vtest); 118 | 119 | for(i=0;i<6;i++){ 120 | free(mtx[i]); 121 | } 122 | free(mtx); 123 | 124 | return(0); 125 | 126 | } 127 | 128 | -------------------------------------------------------------------------------- /libdieharder/rng_superkiss.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rng_superkiss.c 3 | * 4 | * Super KISS based on Usenet posting by G. Marsaglia: 5 | * Period 54767 * 2^1337279 6 | * Adopted in C from David Jones' 7 | * 8 | * Good Practice in (Pseudo) Random Number Generation for 9 | * Bioinformatics Applications 10 | * 11 | * http://www.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf 12 | * 13 | * David Jones, UCL Bioinformatics Group 14 | * E-mail: d.jones@cs.ucl.ac.uk 15 | * Last revised May 7th 2010 16 | * 17 | * 18 | * GSL/GPL packaged for dieharder by Robert G. Brown 01/07/11 19 | * 20 | * David has kindly agreed to make the GPRNG code vailable under the 21 | * GPL so it can be integrated with the dieharder package and/or the 22 | * Gnu Scentific Libraary (GSL). 23 | * 24 | */ 25 | 26 | #include 27 | #define SUPERKISS_QMAX 41790 28 | #define GSL_MT19937_1999 14 29 | 30 | static unsigned long int superkiss_get (void *vstate); 31 | static double superkiss_get_double (void *vstate); 32 | static void superkiss_set (void *vstate, unsigned long int s); 33 | 34 | typedef struct { 35 | /* 36 | * Seed/state variables. Note that superkiss has to be carefully 37 | * seeded, that its first and subsequent refill() calls are expensive, 38 | * so not a good choice if all you're doing is generating five or ten 39 | * random numbers. Should be GREAT for simulations, with effectively 40 | * infinite period and HOPEFULLY good randomness. 41 | */ 42 | 43 | unsigned int Q[SUPERKISS_QMAX]; 44 | unsigned int indx; 45 | unsigned int carry; 46 | unsigned int xcng; 47 | unsigned int xs; 48 | 49 | } superkiss_state_t; 50 | 51 | static unsigned long int superkiss_refill(void *vstate){ 52 | 53 | superkiss_state_t *state = vstate; 54 | int i; 55 | unsigned long long t; 56 | for(i = 0;i < SUPERKISS_QMAX; i++) { 57 | t = 7010176ULL * state->Q[i] + state->carry; 58 | state->carry = (t>>32); 59 | state->Q[i] = ~t; 60 | } 61 | state->indx=1; 62 | return (state->Q[0]); 63 | 64 | 65 | } 66 | 67 | static unsigned long int 68 | superkiss_get (void *vstate) 69 | { 70 | 71 | superkiss_state_t *state = vstate; 72 | 73 | state->xcng = 69069 * state->xcng + 123; 74 | state->xs ^= state->xs<<13; 75 | state->xs ^= state->xs>>17; 76 | state->xs ^= state->xs>>5; 77 | 78 | return ( state->indx < SUPERKISS_QMAX ? state->Q[state->indx++] : superkiss_refill(vstate)) + state->xcng + state->xs; 79 | 80 | } 81 | 82 | static double superkiss_get_double (void *vstate) 83 | { 84 | 85 | return (unsigned int) superkiss_get (vstate) / (double) UINT_MAX; 86 | 87 | } 88 | 89 | static void superkiss_set (void *vstate, unsigned long int s) 90 | { 91 | 92 | /* Initialize automaton using specified seed. */ 93 | superkiss_state_t *state = (superkiss_state_t *) vstate; 94 | 95 | uint seed_seed; 96 | gsl_rng *seed_rng; /* random number generator used to seed uvag */ 97 | int i; 98 | 99 | /* 100 | * superkiss needs MANY initial seeds. They have to be reproducible 101 | * from a single seed in order to be consistent with the GSL. We 102 | * therefore have to do a two step process where we use seed to 103 | * seed an existing GSL generator (say mt19937_1999) and take the 104 | * first 41790 returns as the rest of our seed for this generator. 105 | */ 106 | seed_rng = gsl_rng_alloc(dh_rng_types[GSL_MT19937_1999]); 107 | seed_seed = s; 108 | gsl_rng_set(seed_rng,seed_seed); 109 | for(i = 0;i < SUPERKISS_QMAX;i++){ 110 | state->Q[i] = gsl_rng_get(seed_rng); 111 | } 112 | state->indx=SUPERKISS_QMAX; 113 | state->carry=362436; 114 | state->xcng=1236789; 115 | state->xs=521288629; 116 | 117 | } 118 | 119 | static const gsl_rng_type superkiss_type = 120 | {"superkiss", /* name */ 121 | UINT_MAX, /* RAND_MAX */ 122 | 0, /* RAND_MIN */ 123 | sizeof (superkiss_state_t), 124 | &superkiss_set, 125 | &superkiss_get, 126 | &superkiss_get_double}; 127 | 128 | const gsl_rng_type *gsl_rng_superkiss = &superkiss_type; 129 | -------------------------------------------------------------------------------- /include/dieharder/dieharder_rng_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | *======================================================================== 3 | * See copyright in copyright.h and the accompanying file COPYING 4 | *======================================================================== 5 | */ 6 | 7 | /* 8 | *======================================================================== 9 | * This is being directly adapted from and modified for use in dieharder 10 | * so it can maintain its own independent RNG space of types not limited 11 | * by the GSL's current internal limit of 100. To avoid collisions, 12 | * we'll start our number space above 100, and extend it to 1000. 13 | * 14 | * To be concrete, I'm going to define the following ranges: 15 | * 16 | * 0-99 GSL generators, in GSL order. If it changes, tough. 17 | * 100-199 reserved for spillover if the GSL ends up with >100 generators 18 | * 200-399 libdieharder generators (fixed order from now on) 19 | * 400-499 R-based generators (fixed order from now on) 20 | * 500-599 hardware generators (starting with /dev/random and friends) 21 | * 600-699 user-defined generators (starting with dieharder example) 22 | * 700-999 reserved, e.g. for future integration with R-like environments 23 | * 24 | * I may have to experiment some to determine if there is any problem 25 | * with defining my own gsl_rng_type table of types and then filling it 26 | * first with the GSL routines, then with dieharder's. 27 | *======================================================================== 28 | */ 29 | 30 | #include 31 | 32 | /* #define GSL_VAR */ 33 | /* List new rng types to be added. */ 34 | GSL_VAR const gsl_rng_type *gsl_rng_stdin_input_raw; /* rgb Aug 2008 */ 35 | GSL_VAR const gsl_rng_type *gsl_rng_file_input_raw; 36 | GSL_VAR const gsl_rng_type *gsl_rng_file_input; 37 | 38 | GSL_VAR const gsl_rng_type *gsl_rng_dev_random; 39 | GSL_VAR const gsl_rng_type *gsl_rng_dev_arandom; 40 | GSL_VAR const gsl_rng_type *gsl_rng_dev_urandom; 41 | 42 | GSL_VAR const gsl_rng_type *gsl_rng_r_wichmann_hill; /* edd May 2007 */ 43 | GSL_VAR const gsl_rng_type *gsl_rng_r_marsaglia_mc; /* edd May 2007 */ 44 | GSL_VAR const gsl_rng_type *gsl_rng_r_super_duper; /* edd May 2007 */ 45 | GSL_VAR const gsl_rng_type *gsl_rng_r_mersenne_twister;/* edd May 2007 */ 46 | GSL_VAR const gsl_rng_type *gsl_rng_r_knuth_taocp; /* edd May 2007 */ 47 | GSL_VAR const gsl_rng_type *gsl_rng_r_knuth_taocp2; /* edd May 2007 */ 48 | 49 | GSL_VAR const gsl_rng_type *gsl_rng_ca; 50 | GSL_VAR const gsl_rng_type *gsl_rng_uvag; /* rgb Jun 2007 */ 51 | GSL_VAR const gsl_rng_type *gsl_rng_aes; /* bauer Oct 2009 */ 52 | GSL_VAR const gsl_rng_type *gsl_rng_threefish; /* bauer Oct 2009 */ 53 | GSL_VAR const gsl_rng_type *gsl_rng_kiss; /* rgb Jan 2011 */ 54 | GSL_VAR const gsl_rng_type *gsl_rng_superkiss; /* rgb Jan 2011 */ 55 | GSL_VAR const gsl_rng_type *gsl_rng_XOR; /* rgb Jan 2011 */ 56 | 57 | /* 58 | * rng global vectors and variables for setup and tests. 59 | */ 60 | #define MAXRNGS 1000 61 | 62 | void dieharder_rng_types(); 63 | 64 | extern const gsl_rng_type *dh_rng_types[MAXRNGS]; 65 | extern const gsl_rng_type **gsl_types; /* where all the rng types go */ 66 | 67 | #define ADD(t) {if (i==MAXRNGS) abort(); dh_rng_types[i] = (t); i++; }; 68 | 69 | /* 70 | * Global shared counters for the new types of rngs in the organization 71 | * defined above. 72 | */ 73 | extern unsigned int dh_num_rngs; /* dh rngs available in dieharder */ 74 | extern unsigned int dh_num_gsl_rngs; /* GSL rngs available in dieharder */ 75 | extern unsigned int dh_num_dieharder_rngs; /* dh rngs available in libdieharder */ 76 | extern unsigned int dh_num_R_rngs; /* R-derived rngs available in libdieharder */ 77 | extern unsigned int dh_num_hardware_rngs; /* hardware rngs supported in libdieharder */ 78 | extern unsigned int dh_num_user_rngs; /* user-added rngs */ 79 | extern unsigned int dh_num_reserved_rngs; /* ngs added in reserved space by new UI */ 80 | 81 | extern gsl_rng *rng; /* global gsl random number generator */ 82 | --------------------------------------------------------------------------------