Skip to content

Commit 01609bc

Browse files
authored
28 lognormalfix (#29)
* Fix calculation of sigma
1 parent 76ec06a commit 01609bc

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/SimSharp/Core/Environment.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Collections.Generic;
1010
using System.Diagnostics;
1111
using System.IO;
12-
using System.Linq;
1312
using System.Threading;
1413
using System.Threading.Tasks;
1514

@@ -530,8 +529,7 @@ public double RandLogNormal(double mu, double sigma) {
530529
/// <returns>A log-normal distributed random value.</returns>
531530
public double RandLogNormal2(IRandom random, double mean, double stdev) {
532531
if (stdev == 0) return mean;
533-
var alpha = Math.Sqrt(mean * stdev) / mean;
534-
var sigma = Math.Sqrt(Math.Log(1 + (alpha * alpha)));
532+
var sigma = Math.Sqrt(Math.Log(stdev * stdev / (mean * mean) + 1));
535533
var mu = Math.Log(mean) - 0.5 * sigma * sigma;
536534
return Math.Exp(RandNormal(random, mu, sigma));
537535
}

src/Tests/EnvironmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void PseudoRealtimeEnvTestStopTest() {
179179
var t = Task.Run(() => env.Run(TimeSpan.FromMinutes(1)));
180180
Task.Delay(TimeSpan.FromMilliseconds(200)).Wait();
181181
env.StopAsync();
182-
Task.Delay(TimeSpan.FromMilliseconds(200)).Wait();
182+
Task.Delay(TimeSpan.FromMilliseconds(500)).Wait();
183183
Assert.True(t.IsCompleted);
184184
}
185185

0 commit comments

Comments
 (0)