From d6aadf7ade76b443c74e677ef5030c91b563ceab Mon Sep 17 00:00:00 2001 From: dasMulli Date: Thu, 13 Oct 2016 08:19:52 +0200 Subject: Addressed PR feedback. --- src/mscorlib/src/System/Random.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/mscorlib') diff --git a/src/mscorlib/src/System/Random.cs b/src/mscorlib/src/System/Random.cs index cb5da3c543..87440b2d8d 100644 --- a/src/mscorlib/src/System/Random.cs +++ b/src/mscorlib/src/System/Random.cs @@ -56,7 +56,7 @@ namespace System { } /*========================================================================================= - **Action: Initializes a new instance of the Random class, using a the specified seed value + **Action: Initializes a new instance of the Random class, using a specified seed value ===========================================================================================*/ public Random(int Seed) { int ii; @@ -125,21 +125,23 @@ namespace System { [ThreadStatic] private static Random t_threadRandom; - private static Random s_globalRandom = new Random(GenerateGlobalSeed()); + private static readonly Random s_globalRandom = new Random(GenerateGlobalSeed()); /*=====================================GenerateSeed===================================== **Returns: An integer that can be used as seed values for consecutively creating lots of instances on the same thread within a short period of time. ========================================================================================*/ private static int GenerateSeed() { - if (t_threadRandom == null) { + Random rnd = t_threadRandom; + if (rnd == null) { int seed; lock (s_globalRandom) { seed = s_globalRandom.Next(); } - t_threadRandom = new Random(seed); + rnd = new Random(seed); + t_threadRandom = rnd; } - return t_threadRandom.Next(); + return rnd.Next(); } /*==================================GenerateGlobalSeed==================================== -- cgit v1.2.3