Skip to content

Commit

Permalink
Fix #319 - internal gaussian limit distribution was clipping (#322)
Browse files Browse the repository at this point in the history
- The internal RndGaussLim() function was clipping values outside of the
specified limits. This resulted in a non-gaussian distribution.
- The fix is now discarding any over-limit values.
  • Loading branch information
w7sst authored Jun 14, 2024
2 parents 9a6c10e + f6379dc commit 5fd1dd9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions RndFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ function RndNormal: Single;
end;


{
Compute a limited gaussian distribution by eliminating values outside
of the specified limits. The original implememtation used a clipping
algorithm which resulted in a non-gaussian distribution of the returned
values.
}
function RndGaussLim(AMean, ALim: Single): Single;
begin
Result := AMean + RndNormal * 0.5 * ALim;
Result := Max(AMean-ALim, Min(AMean+ALim, Result));
//Result := AMean + RndNormal * 0.5 * ALim;
//Result := Max(AMean-ALim, Min(AMean+ALim, Result));
repeat
Result := RndNormal * 0.5 * ALim;
until Abs(Result) <= ALim;
Result := AMean + Result;
end;


Expand Down

0 comments on commit 5fd1dd9

Please sign in to comment.