procedure TForm1.Button1Click(Sender: TObject); var i,k:integer; begin randomize; for i:=0 to 100 do begin k:=random(36); if k=36 then showmessage(inttostr(k))else memo1.Lines.Add('No'); end; end;
procedure TfrmMain.Button1Click(Sender: TObject); begin RandomGel6; end; procedure TfrmMain.RandomGel6; var I : Integer; SL : TStringList; tmp : Integer; begin Randomize; SL := TStringList.Create; try for I := 0 to 6 do begin while True do begin tmp := 1 + Random(36); if SL.IndexOf(IntToStr(tmp)) < 0 then begin SL.Append(IntToStr(tmp)); Break; end; end; end; Memo1.Text := SL.Text; finally SL.Free; end; end;
unit uMain;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TfrmMain = class(TForm) Memo1: TMemo; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } procedure RandomGel6; procedure RandomGel1; public { Public declarations } tmpNumber: array [0..6] of Integer ; end;var frmMain : TfrmMain; implementation{$R *.dfm}procedure TfrmMain.Button1Click(Sender: TObject); begin RandomGel6; RandomGel1;end;procedure TfrmMain.RandomGel1; begin Randomize; Edit1.Text :='特码是:'+IntToStr(tmpnumber[6]); end;procedure TfrmMain.RandomGel6; var I : Integer; SL : TStringList; tmp : Integer; begin Randomize; SL := TStringList.Create; try for I := 0 to 6 do begin while True do begin tmp := 1+Random(36); tmpNumber[i]:=tmp; if SL.IndexOf(IntToStr(tmp)) < 0 then begin SL.Append('第'+IntToStr(i+1)+'个号码是:'+IntToStr(tmp)); Break; end; end; end; Memo1.Text := SL.Text; finally SL.Free; end; end;end.
procedure TfrmMain.RandomGel6; var Int36 array[1..36]of integer; i,j,Num:integer; SL:string; tmp: Integer; begin Randomize; for i:=1 to 36 do Int36 := i; Num:=36; for i := 1 to 7 do begin tmp := 1+Random(Num); SL:=SL+inttostr(Int36[tmp]); for j:= tmp to Num-1 do Int36[j]:=Int36[j+1]; dec(Num);//Num:=Num-1; end; Memo1.Text := SL.Text; end;36个球选出一个后停止,剩下35个球再转,得到第二个球,类推……
var
i,k:integer;
begin
randomize;
for i:=0 to 100 do
begin
k:=random(36);
if k=36 then
showmessage(inttostr(k))else
memo1.Lines.Add('No');
end;
end;
begin
RandomGel6;
end;
procedure TfrmMain.RandomGel6;
var
I : Integer;
SL : TStringList;
tmp : Integer;
begin
Randomize;
SL := TStringList.Create;
try
for I := 0 to 6 do
begin
while True do
begin
tmp := 1 + Random(36);
if SL.IndexOf(IntToStr(tmp)) < 0 then
begin
SL.Append(IntToStr(tmp));
Break;
end;
end;
end;
Memo1.Text := SL.Text;
finally
SL.Free;
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TfrmMain = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure RandomGel6;
procedure RandomGel1;
public
{ Public declarations }
tmpNumber: array [0..6] of Integer ;
end;var
frmMain : TfrmMain;
implementation{$R *.dfm}procedure TfrmMain.Button1Click(Sender: TObject);
begin
RandomGel6;
RandomGel1;end;procedure TfrmMain.RandomGel1;
begin
Randomize;
Edit1.Text :='特码是:'+IntToStr(tmpnumber[6]);
end;procedure TfrmMain.RandomGel6;
var
I : Integer;
SL : TStringList;
tmp : Integer;
begin
Randomize;
SL := TStringList.Create;
try
for I := 0 to 6 do
begin
while True do
begin
tmp := 1+Random(36);
tmpNumber[i]:=tmp;
if SL.IndexOf(IntToStr(tmp)) < 0 then
begin
SL.Append('第'+IntToStr(i+1)+'个号码是:'+IntToStr(tmp));
Break;
end;
end;
end;
Memo1.Text := SL.Text;
finally
SL.Free;
end;
end;end.
var
Int36 array[1..36]of integer;
i,j,Num:integer;
SL:string;
tmp: Integer;
begin
Randomize;
for i:=1 to 36 do
Int36 := i;
Num:=36;
for i := 1 to 7 do
begin
tmp := 1+Random(Num);
SL:=SL+inttostr(Int36[tmp]);
for j:= tmp to Num-1 do
Int36[j]:=Int36[j+1];
dec(Num);//Num:=Num-1;
end;
Memo1.Text := SL.Text;
end;36个球选出一个后停止,剩下35个球再转,得到第二个球,类推……