+ int64 version of randomrange() (mantis #16108)

git-svn-id: trunk@15097 -
This commit is contained in:
Jonas Maebe 2010-03-30 20:04:19 +00:00
parent 734f9de2a0
commit 60f8b7fcb1
3 changed files with 70 additions and 0 deletions

1
.gitattributes vendored
View File

@ -10339,6 +10339,7 @@ tests/webtbs/tw15930.pp svneol=native#text/plain
tests/webtbs/tw16004.pp svneol=native#text/plain
tests/webtbs/tw16040.pp svneol=native#text/plain
tests/webtbs/tw16083.pp svneol=native#text/plain
tests/webtbs/tw16108.pp svneol=native#text/plain
tests/webtbs/tw1617.pp svneol=native#text/plain
tests/webtbs/tw1622.pp svneol=native#text/plain
tests/webtbs/tw1623.pp svneol=native#text/plain

View File

@ -418,6 +418,7 @@ function maxvalue(const data : PInteger; Const N : Integer) : Integer;
{ returns random values with gaussian distribution }
function randg(mean,stddev : float) : float;
function RandomRange(const aFrom, aTo: Integer): Integer;
function RandomRange(const aFrom, aTo: Int64): Int64;
{$ifdef FPC_HAS_TYPE_SINGLE}
{ calculates the standard deviation }
@ -1231,6 +1232,12 @@ begin
end;
function RandomRange(const aFrom, aTo: Int64): Int64;
begin
Result:=Random(Abs(aFrom-aTo))+Min(aTo,AFrom);
end;
{$ifdef FPC_HAS_TYPE_SINGLE}
function stddev(const data : array of Single) : float;

62
tests/webtbs/tw16108.pp Normal file
View File

@ -0,0 +1,62 @@
uses
Math;
var
i: longint;
ires: longint;
qres: int64;
begin
randomize;
for i:=1 to 100 do
begin
ires:=randomrange(-4,-7);
if (ires<-7) or
(ires>=-4) then
halt(1);
ires:=randomrange(-7,-4);
if (ires<-7) or
(ires>=-4) then
halt(2);
ires:=randomrange(10,-3);
if (ires<-3) or
(ires>=10) then
halt(3);
ires:=randomrange(-3,10);
if (ires<-3) or
(ires>=10) then
halt(4);
ires:=randomrange(5,10);
if (ires<5) or
(ires>=10) then
halt(5);
ires:=randomrange(10,5);
if (ires<5) or
(ires>=10) then
halt(6);
qres:=randomrange(low(int64)+1,low(int64)+10);
if (qres<low(int64)+1) or
(qres>=low(int64)+10) then
halt(7);
qres:=randomrange(low(int64)+10,low(int64)+1);
if (qres<low(int64)+1) or
(qres>=low(int64)+10) then
halt(8);
qres:=randomrange(int64(10),int64(-3));
if (qres<-3) or
(qres>=10) then
halt(3);
qres:=randomrange(int64(-3),int64(10));
if (qres<-3) or
(qres>=10) then
halt(4);
qres:=randomrange(int64(5),int64(10));
if (qres<5) or
(qres>=10) then
halt(5);
qres:=randomrange(int64(10),int64(5));
if (qres<5) or
(qres>=10) then
halt(6);
end;
end.