From d7007044c20652d8e6108fed2f63f777f9d66355 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sat, 21 Mar 2020 03:11:16 +0300 Subject: [PATCH] Add a note about the Random(...) generators being not thread-safe --- libraries/stdlib/src/kotlin/random/Random.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/stdlib/src/kotlin/random/Random.kt b/libraries/stdlib/src/kotlin/random/Random.kt index 8b0014e1c77..b93b91dab77 100644 --- a/libraries/stdlib/src/kotlin/random/Random.kt +++ b/libraries/stdlib/src/kotlin/random/Random.kt @@ -282,6 +282,8 @@ public abstract class Random { * *Note:* Future versions of Kotlin may change the algorithm of this seeded number generator so that it will return * a sequence of values different from the current one for a given seed. * + * On JVM the returned generator is NOT thread-safe. Do not invoke it from multiple threads without proper synchronization. + * * @sample samples.random.Randoms.seededRandom */ @SinceKotlin("1.3") @@ -295,6 +297,8 @@ public fun Random(seed: Int): Random = XorWowRandom(seed, seed.shr(31)) * *Note:* Future versions of Kotlin may change the algorithm of this seeded number generator so that it will return * a sequence of values different from the current one for a given seed. * + * On JVM the returned generator is NOT thread-safe. Do not invoke it from multiple threads without proper synchronization. + * * @sample samples.random.Randoms.seededRandom */ @SinceKotlin("1.3")