unit1.pas

来自「DELPHI 产生N个不同的随机数。 希望大家能用得上」· PAS 代码 · 共 71 行

PAS
71
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)

    Button1: TButton;


    procedure Button1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
   // MyArray : array of Integer;
   //procedure Rands1();
  end;
  MyArray = array of Integer;
var
  Form1: TForm1;
  a1: MyArray;
implementation

{$R *.dfm}

procedure Rands1(SizeA:integer);
var
  I, J, temp: Integer;
begin
SetLength(a1, SizeA);
  for I := 1 to SizeA do
  begin
    a1[I] := I;
  end;
  Randomize;
  for I := 1 to SizeA do
  begin
    J := Random(SizeA);
    if I <> J then
    begin
      temp := a1[J];
      a1[J] := a1[I];
      a1[I] := Temp;
    end;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  I,Z: Integer;
  a:string;

begin
  Z:= 10;
  Rands1(16);
  for I := 1 to Z do
  begin
    //ShowMessage(IntToStr(a1[I]));
    a:=a +  inttostr(a1[I]) + ',';

  end;
  showmessage(a);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?