Details

This is the updated Middle-Square Method, created by Bernard Widynski in 2017. As we did for the original version, we are going to use the middle six digits of the seed.

Adding a Weyl Sequence clearly improved the quality of this type of PRNG, though it still suffers from a very short period and, as the plot results show, the output isn't very random compared to newer generators. It does, however, pass many of our tests.

Pseudocode

// The current state value
state = 1138;

// Values used for the Weyl Sequence
s = $b5ad4eceda1ce2a9;
w = 0;

// random number generator
function RandomNumber() {

	// Multiply the state by itself
	tmp = state * state;

	// Add the Weyl Sequence
	w = w + s;
	tmp = tmp + w;

	// Add enough padding to make it at least 8 digits
	tmp.pad_left('0', 8);

	// Save the middle 6 digits
	state = tmp.substr( (tmp.length / 2) - 3 , 6 );

	// Return the new value
	return state;

}
			


Test Results

Period Length Test

SeedPeriod LengthResult
11381033Failed
655351580Failed
86753091531Failed
167772162035Failed
1234567892121Failed
Minimum to Pass: 64,000

Plot Test

 

Count the 1s Test

Seed% Bits that are 1sResult
113849.55%Passed
6553549.21%Passed
867530949.32%Passed
1677721649.51%Passed
12345678949.51%Passed
Minimum to Pass: 45%

Dartboard Test

SeedDarts PlacedResult
11381420Failed
655351478Failed
86753091530Failed
167772161390Failed
1234567891457Failed
Minimum to Pass: 2,600

Crush Test

SeedCompression RateResult
1138101.14%Passed
65535101.14%Passed
8675309101.14%Passed
16777216101.14%Passed
123456789101.14%Passed
Minimum to Pass: 95%

Unique Bytes Test

SeedUnique High BytesUnique Low BytesResult
1138172158Failed
65535166163Passed
8675309168168Passed
16777216164170Passed
123456789172151Failed
Minimum to Pass: 160

High/Low Byte Test

SeedHigh After HighHigh After LowLow After HighLow After LowSpreadResult
113820702904290321221615Failed
6553520992884288521311539Failed
867530920702904290421211617Failed
1677721620702904290421211617Failed
12345678920762899289921251597Failed
Maximum to Pass: 500

Distribution Test

Seed113865535867530916777216123456789
0.0 to 0.110181017101910151003
0.1 to 0.29919939869901001
0.2 to 0.399499110061000983
0.3 to 0.49919879789831005
0.4 to 0.5985993991988985
0.5 to 0.6985990992979976
0.6 to 0.710591053105510651070
0.7 to 0.8993996995997989
0.8 to 0.9998996986990992
0.9 to 1.0987985993994997
Spread153139159159157
ResultPassedPassedPassedPassedPassed
Maximum to Pass: 500

Sample Output

7926566690137306283541759727764440665764728463738071966433
598443215369275673898653528654586794210128829810458939517581
14083876104383005845384071695692371760535384210258664532
6872583146249335754723618692245204305399928415558787759746
242045859544489031547456170746790725860107483937101566722012
790543414264324159413271689434462996336234877648293275168
335144958195588938205909266286889256519139577348200671820425
49438350857313140075167082056944433762263123749746548374653
99316765049677912305150364907987992619107235863296008919012
549266607259230614850143479523538017161297781347850613474428


A WFTID Website