亂數取得.......數字 |
答題得分者是:william
|
nlmnrke
一般會員 發表:5 回覆:16 積分:4 註冊:2004-11-17 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
procedure TForm1.Button1Click(Sender: TObject); var X: Byte; Sample: array of Byte; I: Integer; begin //產生Sample SetLength(Sample, Random(10) 1); for I := 0 to Length(SetLength)-1 do Sample[I] := Random(10); //X 代表你要的亂數 X := Sample[Random(Length(Sample))]; end;發表人 - jow 於 2005/11/28 18:21:33 |
nlmnrke
一般會員 發表:5 回覆:16 積分:4 註冊:2004-11-17 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
function GetRandom(const ValueSet: array of integer): integer; begin Result := ValueSet[random(High(ValueSet)-Low(ValueSet) 1)]; end;then... x := GetRandom([1,3,4,5,7,9]); x := GetRandom([2,3,6]); x := GetRandom([0,4,5,8,9]);http://pywong.hk.st |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls; type TArrayofByte = array of Byte; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private function CustomSample(SampleCount: Integer): TArrayOfByte; function CustomRandom(Sample: TArrayOfByte): Byte; end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.CustomRandom(Sample: TArrayOfByte): Byte; begin if Sample = nil then Result := Byte(-1) else Result := Sample[Random(Length(Sample))]; end; function TForm1.CustomSample(SampleCount: Integer): TArrayOfByte; var I: Integer; begin if SampleCount < 1 then Result := nil else begin SetLength(Result, SampleCount); for I := 0 to SampleCount-1 do Result[I] := Random(256);//Sample Range 0..255 end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(CustomRandom(CustomSample(5)))); end; |
nlmnrke
一般會員 發表:5 回覆:16 積分:4 註冊:2004-11-17 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
|
acqua
一般會員 發表:3 回覆:24 積分:20 註冊:2005-09-13 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
根據delphi的Help,將Randomize放置在GetRandom()中,似乎比較不太適當
,Borland建議不要在Loop中重複呼叫Randomize. Description Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.
Do not combine the call to Randomize in a loop with calls to the Random function. Typically, Randomize is called only once, before all calls to Random.
|
nlmnrke
一般會員 發表:5 回覆:16 積分:4 註冊:2004-11-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |