deltarho wrote:A final word on something which has not been mentioned. Bot PCG32II and MsWs have something in common: They are both thread safe.
MSWS (the class, not the PRNG) is thread safe by virtue of it being immutable. The state may be, but the class is not (there's no way to either modify or refer to the internal state from outside the class; you can only access copies of the current state through properties). Recall the code I posted in the second version of the MSWS class:
Code: Select all
? "How to clone your instance..."
var anotherRandomNumber = MsWs( _
for i as integer = 1 to 100
? randomNumber.one(), anotherRandomNumber.one()
This shows a very simple basis for concurrency: all functions (or objects) are to be immutable (and, if at all possible, stateless; but I have yet to see a stateless PRNG =D), so they can be processed in parallel. The above code clones the instance, and then you have two PRNGs that will output the same values, at the same time (provided you call them synchronously, of course). Put each one of them in its own thread, and presto! Multithreaded RNG =D