3 ms·
I would not recommend that circular buffer idea for quantitative calculations. Consider averaging n numbers from a buffer that you've filled with m random vari
by jwmerrill 13y ago
I would not recommend that circular buffer idea for quantitative calculations.
Consider averaging n numbers from a buffer that you've filled with m random variates with m < n: the standard deviation of your average will decrease like 1/sqrt(m), not 1/sqrt(n), so you might as well have just averaged the independent random numbers you produced instead of reusing some of them.
Maybe the circular buffer idea would be useful in non-quantitative contexts, though, e.g. for simulating something in a game or a movie, where all you need is the appearance of randomness.
- StefanKarpinski 13y agoAgreed, that circular buffer thing is bound to do one of two things based on whether the RNG thread or the work thread is faster: a) work slower than RNG – do too much work, wasting CPU; b) work faster than RNG – produce very poor randomness. Neither of these situations is good, and dealing with two threads in the first place is a bit of a complication. If you're going to do that, it's better to synchronize the two threads so that the work thread blocks when it needs more randomness than the RNG thread has produced and vice versa.