RandomReal в LightPT.pas

RandomReal - исправил digits по умолчанию на -1, что означает максимум
This commit is contained in:
Mikhalkovich Stanislav 2023-07-02 15:42:36 +03:00
parent 4ef03daa3d
commit 575046ce5c
10 changed files with 40 additions and 12 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "9";
public const string Build = "0";
public const string Revision = "3299";
public const string Revision = "3304";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=9
%REVISION%=3299
%COREVERSION%=0
%REVISION%=3304
%MINOR%=9
%MAJOR%=3

View file

@ -1,7 +1,5 @@
uses GraphWPF;
function RandomReal(a,b: real): real := Random*(b-a)+a;
type
BallInfo = auto class
x,y,r,dx,dy: real;

View file

@ -2,8 +2,6 @@
const vmax = 50;
function RandomReal(a,b: real): real := Random*(b-a)+a;
type
BallInfo = auto class
x,y,r,vx,vy: real;

View file

@ -1 +1 @@
3.9.0.3299
3.9.0.3304

View file

@ -1 +1 @@
!define VERSION '3.9.0.3299'
!define VERSION '3.9.0.3304'

View file

@ -1700,6 +1700,8 @@ function Random(maxValue: real): real;
function Random(a, b: integer): integer;
/// Возвращает случайное вещественное в диапазоне [a,b)
function Random(a, b: real): real;
/// Возвращает случайное вещественное в диапазоне [a,b] c количеством значащих цифр после точки, равным digits
function RandomReal(a, b: real; digits: integer := -1): real;
/// Возвращает случайный символ в диапазоне от a до b
function Random(a, b: char): char;
/// Возвращает случайное целое в диапазоне
@ -8509,6 +8511,29 @@ begin
Result := a + Random()*(b-a);
end;
function RandomReal(a, b: real; digits: integer): real;
begin
if digits<0 then
Result := Random(a,b)
else begin
// Бывают некорректные данные. Например, найти точку с 2 знаками на [2.736, 2.737]. Тогда возвращать a скажем
var step := 1/10**digits;
Result := Round(Random(a,b),digits);
if Result < a then
begin
Result += step;
if Result > b then
Result := b
end
else if Result > b then
begin
Result -= step;
if Result < a then
Result := a;
end;
end;
end;
function Random(diap: IntRange): integer := Random(diap.Low,diap.High);
function Random(diap: RealRange): real := Random(diap.Low,diap.High);
function Random(diap: CharRange): char := Random(diap.Low,diap.High);

View file

@ -1,7 +1,5 @@
uses GraphWPF;
function RandomReal(a,b: real): real := Random*(b-a)+a;
type
BallInfo = auto class
x,y,r,dx,dy: real;

View file

@ -48,6 +48,8 @@ function Random(n: integer): integer;
function Random: real;
/// Возвращает случайное вещественное в диапазоне [a,b)
function Random(a, b: real): real;
/// Возвращает случайное вещественное в диапазоне [a,b] c количеством значащих цифр после точки, равным digits
function RandomReal(a, b: real; digits: integer := 1): real;
/// Возвращает случайный символ в диапазоне от a до b
function Random(a, b: char): char;
/// Возвращает случайное целое в диапазоне
@ -1029,6 +1031,13 @@ begin
InputList.Add(Result);
end;
function RandomReal(a, b: real; digits: integer): real;
begin
Result := PABCSystem.RandomReal(a, b, digits);
if IsPT then exit;
InputList.Add(Result);
end;
/// Возвращает случайное целое в диапазоне
function Random(diap: IntRange): integer;
begin

View file

@ -1701,7 +1701,7 @@ function Random(a, b: integer): integer;
/// Возвращает случайное вещественное в диапазоне [a,b)
function Random(a, b: real): real;
/// Возвращает случайное вещественное в диапазоне [a,b] c количеством значащих цифр после точки, равным digits
function RandomReal(a, b: real; digits: integer := 1): real;
function RandomReal(a, b: real; digits: integer := -1): real;
/// Возвращает случайный символ в диапазоне от a до b
function Random(a, b: char): char;
/// Возвращает случайное целое в диапазоне