From 126aa730b6726503c0672caac19a898f0c7918da Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 23 Oct 2020 15:37:48 -0700 Subject: [PATCH] bpo-39108: Document threading issues for random.gauss() --- Doc/library/random.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/library/random.rst b/Doc/library/random.rst index 5a9359484d11a8..c243aced986e56 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -319,6 +319,13 @@ be found in any statistics text. deviation. This is slightly faster than the :func:`normalvariate` function defined below. + Multithreading note: When two threads call this function + simultaneously, it is possible that they will receive the + same return value. This can be avoided in three ways. + 1) Have each thread use a different instance of the random + number generator. 2) Put locks around all calls. 3) Use the + slower, but thread-safe :func:`normalvariate` function instead. + .. function:: lognormvariate(mu, sigma)