I was interested in two things: How long to complete the test and how many 'yellow pixels' were left standing, so to speak.
Code: Select all
t = Timer
For j = 1 to 10
For i = 1 to 640*400
PSet ( Int(Rnd*640), Int(Rnd*400) ) ' Replacing the FB Rnds with the other generators
Next
Next
t = Timer - t
What this proved was that PCG32II did very well and was only slightly beaten by CMWC4096 and the generator from Numerical Recipes; the latter being a very fast 32-bit LCG.
What caught my eye was all of the generators left pretty much the same number of yellow pixels standing averaging about 10 to 15 pixels. However, one noticeable exception was FB #4.
From the manual, FB #4 is described as:
4 - Uses a function that is designed to give the same random number sequences as QBASIC. This should be stable across all platforms, and provides 24-bit precision, with a low degree of randomness.
FB #4 fails PractRand at 4KB. PCG32II goes to at least 16TB with Practrand.
FB #4 had between 1 and 3 yellow pixels standing. What this told me was FB #4 whilst not passing muster in the randomness stakes seemed to be doing exceptionally well in the uniformity stakes.
If we take our 640*400 screen and wrote an algorithm to Pset from the left and work its way to the write such that no yellow pixels were left then we would have created a uniform distribution. However, that behaviour would in no way qualify as being random. A random distribution would see yellow pixels changing to blue in an unpredictable manner.
Now Monte Carlo methods are not sensitive to randomness but they are sensitive to uniformity. Most people use good quality random number generators because they tend to uniformity the more random numbers we request. A cryptographic PRNG will eventually produce perfect uniformity but they are very slow in comparison with PRNGs.
In view of this, it occurred to me that FB #4 may be a good candidate for Monte Carlo simulation. So, I ran a Montecarlo test to estimate PI and got this from five runs of 20 million pairs of random numbers and got this.
Code: Select all
FB #4 3.141453 0.9999556105437050 *
PCG32II 3.141148 0.9998583350424872
FB #4 3.141481 0.9999645868824955 *
PCG32II 3.140841 0.9997608048933606
FB #4 3.141667 0.9999762080447450 *
PCG32II 3.141793 0.9999363591313422
FB #4 3.141526 0.9999789108273737 *
PCG32II 3.141880 0.9999084795116608
FB #4 3.141593 0.9999997624103084 *
PCG32II 3.141638 0.9999856296578152
PI = 3.14159265358979323846
The second column of numbers indicates the number of significant figures achieved and * is the better of the two generators in this respect.
FB #4 is the more accurate than PCG32II with every run. Look at the fifth run!
FB #4 is not the fastest generator on the block but it is faster than Mersenne Twister and, clearly, has a better level of uniformity than PCG32II for the same number of random number requests. PCG32II will reach the same level of uniformity but only after more requests than FB #4.
In another thread dodicat wrote:
randomize 4 seems the best for accuracy.
It reaches a steady 5 decimal places after about 20 seconds.
The others never seem to get 5 places even after a coffee run.
That is true.
However, he also wrote:
But it seems to produce the best randomness (5 places in pi/4 within a few seconds).
which is false from both the manual and PractRand.
It has, from the above, the best uniformity before anything else.
I think in the same thread jj2007 and I reckoned that the FB generators should be 'dumped' and replaced by newer generators such as PCG32II. FB #4 should be kept for Monte Carlo simulation if nothing else.
If you are 'into' Monte Carlo simulation and are not using FB #4 it is worthwhile looking at.