隨機生成漢字!

2021-05-27 00:32:54 字數 2946 閱讀 6722

var

aa: string;

bb: array[1..95] of byte;

cc: array[1..95] of byte;

i, j: integer;

begin

i := $a0;

for j := 1 to 95 do

begin

bb[j] := i;

cc[j] := i;

inc(i);

end;

randomize;

for i := 1 to 3 do

begin

aa := aa + chr(bb[random(95)]) + chr(cc[random(95)]);

end;

self.my1.lines.add(aa);

end;

function tfrmpwgenerate.btngenerateclick(sender: tobject): string;

const

intmax_pw_len = 10;

var

i: byte;

s: string;

begin

if cbaz.checked then

s := "abcdefghijklmnopqrstuvwxyz"

else

s := "";

if cbazsmall.checked then

s := s + "abcdefghijklmnopqrstuvwxyz";

if cb09.checked then

s := s + "0123456789";

if s = "" then exit;

result := "";

for i := 0 to intmax_pw_len-1 do

result := result + s[random(length(s)-1)+1];

end;

initialization

randomize;

結果:

ibbfa1mvk2

tmuxiuqjv5

oney1cf6xb

fliuhfdiui

mxak71djaq

b0ytqxdalh

...***********************************

function getrandomstring:string;

var

len,i:byte;

str:string;

begin

len:=random(100);//獲取要隨機生成字元的長度!

for i:=1 to len do

str:=str+chr(random(128));

result:=str;

end;

procedure tform1.btn8click(sender: tobject);

var i,j,ind:dword;

target:string;

usedata:array[0..3] of integer;

tempind:integer;

isinuse:bool;

indstr:string;

begin

for j:=0 to 3 do

usedata[j]:=0;

ind:=0;

while true do

begin

randomize;

tempind:=random(5);

if tempind =0 then continue;

isinuse:=false;

for j:=0 to 3 do

begin

if usedata[j]=tempind then

begin

isinuse:=true;

break;

end;

end;

if not isinuse then

begin

usedata[ind]:= tempind;

inc(ind);

end;

if ind=4 then break;

end;

target :='';

for i:=0 to 3 do

begin

indstr:=indstr+inttostr(usedata[i])+',';

target:= target + copy(edt1.text,usedata[i]*2-1,2);

end;

mmy1.lines.add(format('%s',[indstr]));

mmy1.lines.add(format('%s',[target]));

end;

效果:3,2,4,1,

中個國一

2,3,4,1,

個中國一

3,1,2,4,

中乙個國

4,2,3,1,

國個中一

2,4,1,3,

個國一中

2,4,3,1,

個國中一

1,4,2,3,

一國個中

2,1,4,3,

個一國中

4,2,1,3,

國個一中

1,2,3,4,

乙個中國

2,4,3,1,

個國中一

4,2,3,1,

國個中一

1,3,2,4,

一中個國

4,2,1,3,

國個一中

生成隨機漢字

using system using system.text 此函式在漢字編碼範圍內隨機建立含兩個元素的十六進製制位元組陣列,每個位元組陣列代表乙個漢字,並將 四個位元組陣列儲存在object陣列中。引數 strlength,代表需要產生的漢字個數 public static object crea...

Java 生成隨機漢字名稱

方法一 class randomhan 這種會有繁體字。class randomhan han的使用可以自己設定很多預選漢字,然後通過中文轉unicode 轉碼 或者直接設定 乙個string 漢字陣列,然後隨機取字。public string getchinese long seed throws...

jmeter生成隨機漢字,隨機ip位址

public class random str catch unsupportedencodingexception ex ret str return ret 測試 random str ran newrandom str string content1 新增 ran.randomjianhan ...