function WordRandom(len: integer; PROPIS, rus, eng, num: boolean): string;
var b: array[0..255] of boolean;
i, n: integer;
begin
Result:='';
if not PROPIS and not rus and not eng and not num then
Exit;
for i:=0 to 255 do
b[i]:=false;
if num then
for i:=48 to 57 do
b[i]:=true;
if PROPIS and eng then
for i:=65 to 90 do
b[i]:=true;
if eng then
for i:=97 to 122 do
b[i]:=true;
if PROPIS and rus then
for i:=192 to 223 do
b[i]:=true;
if rus then
for i:=224 to 255 do
b[i]:=true;
n:=0;
while n<len do
begin
Inc(n);
i:=Random(256);
if b[i] then
Result:=Result+Char(i) else
Dec(n);
end;
end;
где:
len – длина строки;
PROPIS – включить прописные буквы;
rus – включить русские буквы;
eng – включить английские буквы;
num – включить цифры.
Например,
WordRandom(5, true, true, true, true)
выведет случайным образом строку длиной в 5 символов (например,
'r5фSЦ').
Примечание. В современных версиях языка Паскаль
русские буквы могут иметь другие коды из-за различия в кодировках.
|