Skip to content

Counter-based pseudorandom number generation algorithm

License

Notifications You must be signed in to change notification settings

Kudesunik/KudesuRandom

Repository files navigation

KudesuRandom

Counter-based pseudorandom number generation algorithm

GitHub last commit GitHub

Description

This algorithm based on middle-square method with Weyl sequence, but with major changes;

It is very fast counter-based random generator which can pass statistical tests faultless with more than 16 TB generated data;

For this generator, seeding is important process: seed should be about half ones and half zeros with irregular template, so this class contains a generator of such seeds;

Algorithm uniformity tested for nextInt() and nextLong() methods by:

  • NIST STS
  • GJrand STS
  • PractRand STS on 16 TB (2^44 bytes) data with no fails;

What for?

I want to make fast and statistical correct algorithm with counter that will allow me to quickly get a pseudo-random value at any given time without overwriting the generator seed. It's all.

Usage

Default
KudesuRandom random = new KudesuRandom();

random.nextInt(); //-1468804468
random.nextLong(); //5938348328185169865
random.nextFloat(); //0.92516685
random.nextDouble(); //0.29415755092917695
random.nextBoolean(); //true
Utility
KudesuRandom random = new KudesuRandom();
		
random.nextIntRange(5); //4
random.nextIntRange(5, 10); //8
random.nextLongRange(5); //2
random.nextLongRange(5000000000000L, 5000000000010L); //5000000000007
Counter
KudesuRandom random = new KudesuRandom();
		
random.getInt(462); //228517850
random.getInt(875); //-250807096
		
random.getInt(462); //228517850
random.getInt(875); //-250807096
		
random.getDouble(7852); //0.5717218313913663
random.getDouble(7853); //0.7288801393591917
		
random.setCounter(7852);
		
random.nextDouble(); //0.5717218313913663
random.nextDouble(); //0.7288801393591917
Multithread

Make your own threads with random.setCounter() and set same seed value :)

Tests

PractRand Statistical Test Suite and performance tests results:

PractRand STS

nextInt() ~/Programming/Random/PractRand$ ./test/test-final-int | ./RNG_test stdin32 -tlmaxonly
RNG_test using PractRand version 0.95
RNG = RNG_stdin32, seed = unknown
test set = core, folding = standard (32 bit)

rng=RNG_stdin32, seed=unknown
length= 256 megabytes (2^28 bytes), time= 3.8 seconds
no anomalies in 168 test result(s)

rng=RNG_stdin32, seed=unknown
length= 512 megabytes (2^29 bytes), time= 8.6 seconds
no anomalies in 180 test result(s)

rng=RNG_stdin32, seed=unknown
length= 1 gigabyte (2^30 bytes), time= 17.4 seconds
no anomalies in 194 test result(s)

rng=RNG_stdin32, seed=unknown
length= 2 gigabytes (2^31 bytes), time= 33.8 seconds
no anomalies in 205 test result(s)

rng=RNG_stdin32, seed=unknown
length= 4 gigabytes (2^32 bytes), time= 64.4 seconds
no anomalies in 217 test result(s)

rng=RNG_stdin32, seed=unknown
length= 8 gigabytes (2^33 bytes), time= 126 seconds
no anomalies in 230 test result(s)

rng=RNG_stdin32, seed=unknown
length= 16 gigabytes (2^34 bytes), time= 261 seconds
no anomalies in 240 test result(s)

rng=RNG_stdin32, seed=unknown
length= 32 gigabytes (2^35 bytes), time= 529 seconds
no anomalies in 251 test result(s)

rng=RNG_stdin32, seed=unknown
length= 64 gigabytes (2^36 bytes), time= 1068 seconds
no anomalies in 263 test result(s)

rng=RNG_stdin32, seed=unknown
length= 128 gigabytes (2^37 bytes), time= 2120 seconds
no anomalies in 273 test result(s)

rng=RNG_stdin32, seed=unknown
length= 256 gigabytes (2^38 bytes), time= 4247 seconds
no anomalies in 284 test result(s)

rng=RNG_stdin32, seed=unknown
length= 512 gigabytes (2^39 bytes), time= 8574 seconds
no anomalies in 295 test result(s)

rng=RNG_stdin32, seed=unknown
length= 1 terabyte (2^40 bytes), time= 17166 seconds
no anomalies in 304 test result(s)

rng=RNG_stdin32, seed=unknown
length= 2 terabytes (2^41 bytes), time= 34151 seconds
no anomalies in 313 test result(s)

rng=RNG_stdin32, seed=unknown
length= 4 terabytes (2^42 bytes), time= 68623 seconds
no anomalies in 323 test result(s)

rng=RNG_stdin32, seed=unknown
length= 8 terabytes (2^43 bytes), time= 137222 seconds
no anomalies in 331 test result(s)

rng=RNG_stdin32, seed=unknown
length= 16 terabytes (2^44 bytes), time= 264083 seconds
no anomalies in 339 test result(s)

rng=RNG_stdin32, seed=unknown
length= 32 terabytes (2^45 bytes), time= 489072 seconds
Test Name Raw Processed Evaluation
[Low1/32]TMFn(2+13):wl R= +26.0 p~= 9e-9 very suspicious
...and 346 test result(s) without anomalies
nextLong() ~/Programming/Random/PractRand$ ./test/test-final-long | ./RNG_test stdin64 -tlmaxonly
RNG_test using PractRand version 0.95
RNG = RNG_stdin64, seed = unknown
test set = core, folding = standard (64 bit)

rng=RNG_stdin64, seed=unknown
length= 256 megabytes (2^28 bytes), time= 3.7 seconds
no anomalies in 213 test result(s)

rng=RNG_stdin64, seed=unknown
length= 512 megabytes (2^29 bytes), time= 8.7 seconds
no anomalies in 229 test result(s)

rng=RNG_stdin64, seed=unknown
length= 1 gigabyte (2^30 bytes), time= 17.5 seconds
no anomalies in 246 test result(s)

rng=RNG_stdin64, seed=unknown
length= 2 gigabytes (2^31 bytes), time= 34.3 seconds
no anomalies in 263 test result(s)

rng=RNG_stdin64, seed=unknown
length= 4 gigabytes (2^32 bytes), time= 64.9 seconds
no anomalies in 279 test result(s)

rng=RNG_stdin64, seed=unknown
length= 8 gigabytes (2^33 bytes), time= 126 seconds
no anomalies in 295 test result(s)

rng=RNG_stdin64, seed=unknown
length= 16 gigabytes (2^34 bytes), time= 245 seconds
no anomalies in 311 test result(s)

rng=RNG_stdin64, seed=unknown
length= 32 gigabytes (2^35 bytes), time= 478 seconds
no anomalies in 325 test result(s)

rng=RNG_stdin64, seed=unknown
length= 64 gigabytes (2^36 bytes), time= 949 seconds
no anomalies in 340 test result(s)

rng=RNG_stdin64, seed=unknown
length= 128 gigabytes (2^37 bytes), time= 1865 seconds
no anomalies in 355 test result(s)

rng=RNG_stdin64, seed=unknown
length= 256 gigabytes (2^38 bytes), time= 3719 seconds
no anomalies in 369 test result(s)

rng=RNG_stdin64, seed=unknown
length= 512 gigabytes (2^39 bytes), time= 7492 seconds
no anomalies in 383 test result(s)

rng=RNG_stdin64, seed=unknown
length= 1 terabyte (2^40 bytes), time= 15002 seconds
no anomalies in 397 test result(s)

rng=RNG_stdin64, seed=unknown
length= 2 terabytes (2^41 bytes), time= 29816 seconds
no anomalies in 409 test result(s)

rng=RNG_stdin64, seed=unknown
length= 4 terabytes (2^42 bytes), time= 59935 seconds
no anomalies in 422 test result(s)

rng=RNG_stdin64, seed=unknown
length= 8 terabytes (2^43 bytes), time= 119886 seconds
no anomalies in 434 test result(s)

rng=RNG_stdin64, seed=unknown
length= 16 terabytes (2^44 bytes), time= 233727 seconds
no anomalies in 445 test result(s)

rng=RNG_stdin64, seed=unknown
length= 32 terabytes (2^45 bytes), time= 432759 seconds
no anomalies in 455 test result(s)

Performance

Performed on JMH (jmh-core-1.21)

alt text

Build

This is Java Ant project.

Contributors

When you're ready to submit your code, just make a pull request.

Reporting bugs

  1. Start by searching issue tracker for duplicates;
  2. Create a new issue, explaining the problem in proper detail.

License

MIT License. See LICENSE file for details.

About

Counter-based pseudorandom number generation algorithm

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages