Skip to content

Commit

Permalink
Fix #319 - internal gaussian limit distribution was clipping
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 committed Jun 9, 2024
1 parent 36fe54e commit f6379dc
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 f6379dc

Please sign in to comment.