diff options
| author | stderr64 <stderr64@null.net> | 2026-09-24 20:49:27 +0300 |
|---|---|---|
| committer | stderr64 <stderr64@null.net> | 2026-09-24 20:49:27 +0300 |
| commit | f54963e1364568d8f4f6e1a5be1646d4c5e7a94e (patch) | |
| tree | 447191762cf030afce72724b8374b06348feab2d /tests/test_statistical_properties.py | |
| download | libxorshift-f54963e1364568d8f4f6e1a5be1646d4c5e7a94e.tar.gz libxorshift-f54963e1364568d8f4f6e1a5be1646d4c5e7a94e.tar.zst | |
First commit
Diffstat (limited to 'tests/test_statistical_properties.py')
| -rwxr-xr-x | tests/test_statistical_properties.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/test_statistical_properties.py b/tests/test_statistical_properties.py new file mode 100755 index 0000000..1346293 --- /dev/null +++ b/tests/test_statistical_properties.py @@ -0,0 +1,73 @@ +#!/usr/bin/python3 -u +import sys; +import argparse; +from ctypes import *; +import numpy as np; + +aparser = argparse.ArgumentParser(); +aparser.add_argument( "--count", type=int, required=True, help="Amount of number combinations to generate" ); +aparser.add_argument( "--num-count", type=int, required=True, help="Amount of numbers in each combination generated" ); +aparser.add_argument( "--min", type=int, required=True, help="Minimum number" ); +aparser.add_argument( "--max", type=int, required=True, help="Maximum number" ); +args = aparser.parse_args(); +del aparser; + +if ( args.max <= args.min ): + del args; + print( "Error: maximum number must be more than minimum" ); + sys.exit( -1 ); + +libxorshift = CDLL( "../build/libxorshift.so" ); +libxorshift.initialize_states.restype = c_bool; +libxorshift.get_uniform_uint.restype = c_uint; +libxorshift.get_uniform_uint.argtypes = [c_uint, c_uint]; + +if ( libxorshift.initialize_states() is c_bool(False) ): + print( "Error: failed to initialize RNG states" ); + del libxorshift; + sys.exit( -1 ); + +generated_combinations = []; +generated_sum = 0; + +current_combination = []; +gen_num = 0; + +for c_count in range( 0, args.count ): + for bcount in range( 0, args.num_count ): + gen_num = int( libxorshift.get_uniform_uint(c_uint(args.min), c_uint(args.max)) ); + generated_sum += gen_num; + current_combination.append( gen_num ); + generated_combinations.append( current_combination ); + current_combination = []; + +del current_combination, gen_num; + +print( "Statistical properties results" ); +print( "-----" ); + +print( "Each combination's mean value" ); +print( "-----" ); + +combination_str = None; + +for gen_combination in generated_combinations: + combination_str = ", ".join( list(map(str, gen_combination)) ); + print( f"Combination {combination_str} has mean {np.mean(gen_combination)}" ); + +del combination_str; + +print( "-----" ); +print( "Overall statistical properties" ); +print( "-----" ); + +print( f"Expected mean overall: {(args.max / 2) * args.num_count}" ); +print( f"Actual overall mean: {generated_sum / args.count}" ); + +print( "-----" ); + +del generated_sum, generated_combinations; + +del libxorshift; +del args; +sys.exit( 0 ); |
