const maxK=39;
function getNumber(k:word):word
begin
do
result:=Random(maxK);
until result < K ;
end;
//调用
var x:array[0..3] of word;
begin
randomize;
do
x[0]:=Random(maxK);
until x[0] > 4;//取第一位数,不能小于4
for i:=1 to 3 do begin
x:=getNumber(x[i-1]);
end;