-3
我想知道如何創建一個隨機化的字符串,它具有設置的長度範圍,該範圍是8到24個字符,而不是它是一個固定的長度,如10個。隨機函數在德爾福創建一個長度範圍
我想知道如何創建一個隨機化的字符串,它具有設置的長度範圍,該範圍是8到24個字符,而不是它是一個固定的長度,如10個。隨機函數在德爾福創建一個長度範圍
Program RandomString;
// Get a random character from A to Z
function GetRandomCharacter: char;
begin
// Use A random value from 0 to 25 and add that to A
Result := 'A';
Inc(Result, Random(26));
end;
// Get a random string of characters from A to Z
// with a length from 8 to 24 characters
function GetRandomString: string;
var
Length: Integer;
I: Integer;
begin
// Get a random length to use from 8 to 24
Length:= 8 + Random(17);
// Create a string of random characters with the desired length
Result := '';
for I:= 1 to Length do
begin
Result := Result + GetRandomCharacter;
end;
end;
begin
// Execute Randomize only once in the application
Randomize;
Writeln(GetRandomString);
end.
你對這項任務有什麼特別的問題? –