f" have repeated ourselves after {counter} steps"
f" with {number}.")
</syntaxhighlight>
==Recent developments==
In the book "Random Numbers and Computers”<ref>{{cite book | title = Random Numbers and Computers | last = Kneusel | first = Ron | publisher = Springer | year = 2018 | edition = 1 | pages = 13-14 }}</ref>, Kneusel states the following:
“Interestingly, recently (as of 2017) the middle square method has resurfaced. In "Middle Square Weyl Sequence RNG"<ref name="mswsrng">{{cite arXiv | last=Widynski | first=Bernard | eprint=1704.00358v5 | title=Middle Square Weyl Sequence RNG | date=April 2017}}</ref> Widynski proposes a straightforward modification of the middle square algorithm which results in a very fast generator with a respectable period, excellent results in randomness tests, and easy application in parallel”.
A [[Weyl sequence]] is used to run the middle square. The [[Weyl sequence]] provides uniformity and a known minimum period; the middle square provides randomization. The combined generator passes very stringent tests of randomness including the BigCrush<ref name="TestU01">L’Ecuyer, Pierre; Simard, Richard (2007), [http://simul.iro.umontreal.ca/testu01/tu01.html TestU01 BigCrush].</ref> and PractRand<ref name = "PractRand">Doty-Humphrey, Chris (2018), "[http://pracrand.sourceforge.net Practically Random: C++ library of statistical tests for RNGs.]" version 0.94.</ref> tests. Many commonly used RNGs do not pass these tests.
A [[C_(programming_language)|C]] language implementation is shown below.
<syntaxhighlight lang="c">
#include <stdint.h>
uint64_t x = 0, w = 0, s = 0xb5ad4eceda1ce2a9;
inline static uint32_t msws() {
x *= x; /* Compute square of x */
x += (w += s); /* Add Weyl sequence */
return x = (x>>32) | (x<<32); /* Rotate and return 32 bits from middle */
}
</syntaxhighlight>
A [[Counter-based random number generator (CBRNG) | counter-based]] version was published in 2020, “Squares: A Fast Counter-Based RNG”<ref>{{cite arXiv| last=Widynski | first=Bernard | arxiv=2004.06278v3 | title=Squares: A Fast Counter-Based RNG | date=April 2020}}</ref>. [[Counter-based random number generator (CBRNG) | Counter-based]] RNGs are well suited to parallel processing<ref>{{Cite conference|title = Parallel random numbers: as easy as 1, 2, 3|last = Salmon|first = John|date = 2011|book-title = Proceedings of 2011 International Conference for High Performance Computing, Networking, Storage and Analysis, Article No. 16|doi = 10.1145/2063384.2063405|last2 = Moraes|first2 = Mark|last3 = Dror|first3 = Ron|last4 = Shaw|first4 = David}}</ref>. Four rounds of squaring are applied to a counter to produce a random output. Squares may be the fastest RNG in this category. The squares generator is shown below.
<syntaxhighlight lang="c">
#include <stdint.h>
inline static uint32_t squares(uint64_t ctr, uint64_t key) {
uint64_t x, y, z;
y = x = ctr * key; z = y + key; /* Compute ctr*key and (ctr+1)*key */
x = x*x + y; x = (x>>32) | (x<<32); /* Round 1 */
x = x*x + z; x = (x>>32) | (x<<32); /* Round 2 */
x = x*x + y; x = (x>>32) | (x<<32); /* Round 3 */
return (x*x + z) >> 32; /* Round 4 */
}
</syntaxhighlight>
|