Browse Source

make Random() thread safety (#596)

Sxul07 6 years ago
parent
commit
a4e1c55b7e
1 changed files with 7 additions and 2 deletions
  1. 7 2
      Jint/Native/Math/MathInstance.cs

+ 7 - 2
Jint/Native/Math/MathInstance.cs

@@ -9,7 +9,7 @@ namespace Jint.Native.Math
 {
 {
     public sealed class MathInstance : ObjectInstance
     public sealed class MathInstance : ObjectInstance
     {
     {
-        private static readonly Random _random = new Random();
+        private Random _random;
 
 
         private MathInstance(Engine engine) : base(engine, "Math")
         private MathInstance(Engine engine) : base(engine, "Math")
         {
         {
@@ -808,8 +808,13 @@ namespace Jint.Native.Math
             return System.Math.Pow(x, y);
             return System.Math.Pow(x, y);
         }
         }
 
 
-        private static JsValue Random(JsValue thisObject, JsValue[] arguments)
+        private JsValue Random(JsValue thisObject, JsValue[] arguments)
         {
         {
+            if(_random == null)
+            {
+                _random = new Random();
+            }
+            
             return _random.NextDouble();
             return _random.NextDouble();
         }
         }