From f6379dcc86e885a97c3590eb3e1b7580e60698c9 Mon Sep 17 00:00:00 2001 From: Mike Brashler Date: Sun, 9 Jun 2024 16:24:39 -0700 Subject: [PATCH] Fix #319 - internal gaussian limit distribution was clipping - 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. --- RndFunc.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/RndFunc.pas b/RndFunc.pas index 2acfd5b..0e87daf 100644 --- a/RndFunc.pas +++ b/RndFunc.pas @@ -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;