产生一个随机数,大家看看有更高级的分享一下哈[已解决]
本帖最后由 heroxianf 于 2018-1-24 14:38 编辑MsgBox(0, 0, _random_number())
Func _random_number($num = 8)
Local $random_number
Local $data = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,,a,b,c,d,e,f,g,h,i' & _
'j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,~,!,@,#,$,%,^,&,*'
Local $data_arr = StringSplit($data, ',')
For $i = 0 To $num
$random_number &= $data_arr
Next
Return $random_number
EndFunc
一般的使用场景用 @MSEC 再顺搭一两个字母就足够随机了… 做个记录~
For $i = 0 To 10
Local $data = _random_number()
ConsoleWrite($data & @CRLF)
Next
Func _random_number($num = 8)
Local $random_number
Local $data = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,,a,b,c,d,e,f,g,h,i' & _
'j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,~,!,@,#,$,%,^,&,*'
Local $data_arr = StringSplit($data, ',')
If $num > UBound($data_arr) - 1 Then $num = UBound($data_arr) - 1
If $num < 1 Then $num = 1
For $i = 1 To $num
$random_number &= $data_arr
Next
Return $random_number
EndFunc
一切为了随机数
设定一个随机数站位 最小值和最大值
For $i = 0 To 10
Local $data = _random_number(5, 10)
ConsoleWrite($data & @CRLF)
Next
Func _random_number($minimum = 2, $maximum = 8)
Local $random_number
Local $data = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,,a,b,c,d,e,f,g,h,i' & _
'j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,~,!,@,#,$,%,^,&,*'
Local $data_arr = StringSplit($data, ',')
If $maximum > UBound($data_arr) - 1 Then $maximum = UBound($data_arr) - 1
If $maximum < 1 Then $maximum = 8
If $minimum < 1 Then $minimum = 2
If $minimum > $maximum Then $minimum = $maximum
Local $num = Random($minimum, $maximum, 1)
For $n = 1 To $num
$random_number &= $data_arr
Next
Return $random_number
EndFunc
感觉有点繁琐 回复 3# heroxianf
like this?;ACN@yamakawa
Local $random
For $i = 0 To 7
$random = _ran(9)
ConsoleWrite($random & @CRLF)
Next
Func _ran($num)
If Not $num Then $num = 8
Local $string
For $i = 0 To $num - 1
$string &= ChrW(Random(33,126,1))
Next
Return $string
EndFunc
回复 4# haijie1223
发哥有什么奇妙的法子,分享一下哇,学习学习。 回复 5# yamakawa
ChrW(Random(33,126,1))
你这个chrW里的随机范围是如何查到的? 33, 126 ConsoleWrite(_random(8) & @CRLF)
Func _random($num = 7)
If Not IsNumber($num) Then $num = 7
Local $ret = ''
For $i = 0 To $num - 1
$ret &= Chr(Random(0, 255, 1))
Next
Return $ret
EndFunc ;==>_random 学习一下,不错··· 好好学习天天向上 回复 7# heroxianf
http://www.robelle.com/library/smugbook/ascii.html 回复 8# haijie1223
0到255有点不妥吧。。。。不可打印字符也包括在内了 回复 13# yamakawa
谢谢,收藏了先。
页:
[1]