aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs
diff options
context:
space:
mode:
authorAndrew Rabert <6550543+nvllsvm@users.noreply.github.com>2019-01-19 15:11:50 -0500
committerGitHub <noreply@github.com>2019-01-19 15:11:50 -0500
commit55538764fa06a64795c099fc6496df9dbb4156bd (patch)
tree8c1f94861ecebdf634b70a7265945b6f8f13aff1 /Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs
parent3b52035ee064a5d9aa215d9515211d4508585d39 (diff)
parentc5430f86b0b5863482e7c4f7e55a79c7d88c133b (diff)
Merge pull request #575 from EraYaN/reformat
Reformat all C# server code to conform with code standards
Diffstat (limited to 'Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs')
-rw-r--r--Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs76
1 files changed, 38 insertions, 38 deletions
diff --git a/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs b/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs
index d55ca80df..5b2fce60b 100644
--- a/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs
+++ b/Emby.Server.Implementations/TextEncoding/NLangDetect/Extensions/RandomExtensions.cs
@@ -1,51 +1,51 @@
-using System;
+using System;
namespace NLangDetect.Core.Extensions
{
- public static class RandomExtensions
- {
- private const double _Epsilon = 2.22044604925031E-15;
-
- private static readonly object _mutex = new object();
-
- private static double _nextNextGaussian;
- private static bool _hasNextNextGaussian;
-
- /// <summary>
- /// Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
- /// The general contract of nextGaussian is that one double value, chosen from (approximately) the usual normal distribution with mean 0.0 and standard deviation 1.0, is pseudorandomly generated and returned.
- /// </summary>
- /// <remarks>
- /// Taken from: http://download.oracle.com/javase/6/docs/api/java/util/Random.html (nextGaussian())
- /// </remarks>
- public static double NextGaussian(this Random random)
+ public static class RandomExtensions
{
- lock (_mutex)
- {
- if (_hasNextNextGaussian)
- {
- _hasNextNextGaussian = false;
+ private const double _Epsilon = 2.22044604925031E-15;
- return _nextNextGaussian;
- }
+ private static readonly object _mutex = new object();
- double v1, v2, s;
+ private static double _nextNextGaussian;
+ private static bool _hasNextNextGaussian;
- do
+ /// <summary>
+ /// Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
+ /// The general contract of nextGaussian is that one double value, chosen from (approximately) the usual normal distribution with mean 0.0 and standard deviation 1.0, is pseudorandomly generated and returned.
+ /// </summary>
+ /// <remarks>
+ /// Taken from: http://download.oracle.com/javase/6/docs/api/java/util/Random.html (nextGaussian())
+ /// </remarks>
+ public static double NextGaussian(this Random random)
{
- v1 = 2.0 * random.NextDouble() - 1.0; // between -1.0 and 1.0
- v2 = 2.0 * random.NextDouble() - 1.0; // between -1.0 and 1.0
- s = v1 * v1 + v2 * v2;
- }
- while (s >= 1.0 || Math.Abs(s - 0.0) < _Epsilon);
+ lock (_mutex)
+ {
+ if (_hasNextNextGaussian)
+ {
+ _hasNextNextGaussian = false;
+
+ return _nextNextGaussian;
+ }
- double multiplier = Math.Sqrt(-2.0 * Math.Log(s) / s);
+ double v1, v2, s;
- _nextNextGaussian = v2 * multiplier;
- _hasNextNextGaussian = true;
+ do
+ {
+ v1 = 2.0 * random.NextDouble() - 1.0; // between -1.0 and 1.0
+ v2 = 2.0 * random.NextDouble() - 1.0; // between -1.0 and 1.0
+ s = v1 * v1 + v2 * v2;
+ }
+ while (s >= 1.0 || Math.Abs(s - 0.0) < _Epsilon);
- return v1 * multiplier;
- }
+ double multiplier = Math.Sqrt(-2.0 * Math.Log(s) / s);
+
+ _nextNextGaussian = v2 * multiplier;
+ _hasNextNextGaussian = true;
+
+ return v1 * multiplier;
+ }
+ }
}
- }
}