本帖最后由 sanmoking 于 2009-12-23 15:24 编辑
很简单的啊,等我一下.$txt = ""
for $t = 1 to 10 ;生成10个字符串
for $i = 1 to 16 ;字符串长度16位
$test =Random (1,3,1)
if $test = 1 Then $x = Chr(Random(48,57,1));生成数字
if $test = 2 Then $x = Chr(Random(97,122,1));生成小写字母
if $test = 3 Then $x = Chr(Random(65,90,1));生成大写字母
$txt = $txt&$x
Next
$txt = $txt&@CRLF
Next
MsgBox(0,"随机字符串",$txt)
写入文本文件的部分我就不管了/////
更新一下:$txt = ""
for $t = 1 to 10 ;生成10个字符串
for $i = 1 to Random (6,10,1) ;字符串长度随机6-10位
$test =Random (1,3,1)
if $test = 1 Then $x = Chr(Random(48,57,1));生成数字
if $test = 2 Then $x = Chr(Random(97,122,1));生成小写字母
if $test = 3 Then $x = Chr(Random(65,90,1));生成大写字母
$txt = $txt&$x
Next
$txt = $txt&@CRLF
Next
MsgBox(0,"随机字符串",$txt)
再更新一下,如果算上常规符号的话,更简单,如下:$txt = ""
for $t = 1 to 10 ;生成10个字符串
for $i = 1 to Random (6,10,1) ;字符串长度随机6-10位
$txt = $txt&Chr(Random(33,126,1))
Next
$txt = $txt&@CRLF
Next
MsgBox(0,"随机字符串",$txt)
很有兴致,再来一个,生成[小写字母+数字+大写字母]格式的字符串,非乱序,如下$txt = ""
for $t = 1 to 10 ;生成10个字符串
$usern1 = ""
for $u = 1 to 6 ;生成6位小写字母
$usern1 = $usern1&Chr (Random (97,122, 1 ))
Next
$usern2 = ""
for $u = 1 to 4 ;生成4位数字
$usern2 = $usern2&Random (0,9,1)
Next
$usern3 = ""
for $u = 1 to Random (1,3,1);生成1-3位大写字母
$usern3 = $usern3&Chr(Random(65,90,1))
Next
$txt = $txt&$usern1&$usern2&$usern3&@CRLF
Next
MsgBox(0,"随机字符串",$txt)
|