# Algorithm Implementation/Pseudorandom Numbers/Wichmann-Hill (1982) PRNG
## Visual Basic

This algorithm has behavior that is broadly similar to that of the built-in VBA Rnd function, and this is perhaps not surprising since it was the basis of the Excel Rand function for quite some time. A short summary is given here:
* The Randomize function is used to set the working variables located at module level. In turn, these variables are used at every stage to calculate RndX outputs and to re-calculate their own values, ready for the next RndX call.
* RandomizeX sets variables using an input from the system timer when it is called without a parameter. When given a parameter, the output stream of characters generated will be distinct and repeatable for that parameter. This latter state applies when no parameter for RndX is given, or if given, provided that it is a positive number.
* The most common configuration, and most useful, calls RandomizeX before RndX, both without parameters. However, if RandomizeX is not included in the code, the work variable defaults that are used by RndX at startup lead to a corresponding default output stream of characters. This same stream is repeated whenever RndX is run without first calling RandomizeX.
* Adding positive parameters for RndX will not seed the generation process. Apart from the starup defaults for RndX, all seeding depends directly or indirectly on having RandomizeX in the code.
* Refer to the drop box below for a complete tabulation of the parameter settings and their outcomes.
PRNG RndX and RandomizeX Parameter Details :
RndX and RandomizeX Parameter Details :
| RandomizeX parameter | RndX parameter | Behaviour of function (assuming coding is to produce a sequence) |
| none. | none | PRNG stream determined by runtime sampling of the computer’s system timer. Stream uncertain. |
| none | positive | PRNG stream determined by runtime sampling of the computer’s system timer. Stream uncertain. Positive parameters of RndX do not affect it at all. |
| none | negative | One number, repeatable, and each one different and depending on the value of parameter. Example; RndX(-3) leads to 0.05079271 |
| none | zero | One number, repeatable, decided by runtime sampling of the computer’s system timer; Example; sequence is 0.1741…, 01741… |
| numeric$^2$ | none | PRNG stream, repeatable, and each one different and depending on the value of parameter. |
| numeric | positive | PRNG stream, repeatable, and each one different and depending on the value of parameter. Positive parameters of RndX do not affect it at all. |
| numeric | negative | One number, repeatable, and each one different and depending on the value of RndX parameter. The RandomizeX parameter value has no effect at all. Example; RndX(-51) leads to 0.8634… |
| numeric | zero | One number, repeatable, and each one different and depending on the value of parameter. Example; RandomizeX(2346) leads to 0.2322… |
| function not used | none | Default PRNG stream, repeatable, and always same. Example; sequence is 0.8952…, 0.1114…, 0.9395… |
| function not used | positive | Default PRNG stream, repeatable, and always same. Example; sequence is 0.8952…, 0.1114…, 0.9395… |
| function not used$^1$ | negative or zero | One number, repeatable, and each one different and depending on the value of parameter. Example; RndX(0) = 0.8694...: -5 = 0.0846… |

## References

* Wichmann, Brian; Hill, David (1982), Algorithm AS183: An Efficient and Portable Pseudo-Random Number Generator, Journal of the Royal Statistical Society. Series C