parameter
  pAverage  : ( 1, real, 'Average', '', '1' );
  pRange    : ( 2, real, 'Range',   '', '1' );
  pBreak    : ( 3, real, 'Break',   '', '0' );
  pError    : ( 4, real, 'Error',   '', '0' );
  pDrift    : ( 5, real, 'Drift',   '', '0' );

const
  cPI = 3.1415926536;

var
  vrActiveDuts : vector;
  vrIndex : real;

step

  if Math.Random < pBreak then begin
    GlobalVar.Set('AbortBySimulation', 1);
    AbortTest;
  end;

  vrActiveDuts := ActiveDuts;

  for vrIndex := 1 to Len(vrActiveDuts) do begin

    if Math.Random < pError then begin
      SetValueEx (vrActiveDuts[vrIndex], Step.UpperLimit + Math.Random * (Step.UpperLimit - Step.LowerLimit) / 10);
    end else begin
      SetValueEx (vrActiveDuts[vrIndex], (pAverage + pDrift * (Step.UpperLimit - Step.LowerLimit)) + pRange * Math.Sqrt(-2.0 * Math.Log(Math.Random)) * Math.Sin(2.0 * cPI * Math.Random));
    end;

  end;

  DateTime.Delay(Math.Random * Val(RegForm.Get('RFE_STEPDELAY'),0), true);

end.
