-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.
你对这项任务有什么特别的问题? –