I haven't found any clear and concise information on this specific topic, so I'd like to ask this relatively simple question for myself and anyone else who comes across this.
Using Visual C++, how would I create a random number with a, say, normal distribution?
There is a seemingly thorough discussion of this here:
but I don't understand the lingo and would really appreicate instructions on how to generate a random, normally distributed number in a thread-safe manner.
Just use normal_distribution (it's not just VC++, it's a standard C++ class). It takes a mean (default 0.0) and a standard deviation (default 1.0) as arguments:
That is one possibility. This would give normally distributed random values for each thread.
If the requirement is for normally distributed random values across all threads in the program, create just one instance of the engine and protect it with mutual exclusion. For example:
It is highly recommended that you use rand_s() Microsoft extension function which is thread-safe (internally calls RtlGenRandom API and is available on windows xp or higher).
Highly recommended by whom? The existing answer directly addresses the OP's requirements, whereas rand_s() isn't even a standard function. That, and it is a terribly simple RNG, with a pseudo-random distribution.
RE rand_s(); I have it on good authority that the Visual C++ variant of the rand() function is itself already thread safe, so using rand_s() in VC++ isn't necessary. I've been using rand() for generating random integers in multiple threads without any issues.