求教算法,顺序生成mac地址![已解决]
本帖最后由 tsys 于 2011-12-25 13:52 编辑想生成mac地址如BC-AE-C5-BF-??-?? ,想让后四位顺序生成,其中包括0-9 A-F,不是随机生成哦,还请高手指教 Local $time = TimerInit()
Local $str='BC-AE-C5-BF-'
For $a = 0 To 15
For $b = 0 To 15
For $c = 0 To 15
For $d = 0 To 15
$MAC = $str & StringFormat(_Num_to_Letter($a)) & StringFormat(_Num_to_Letter($b)) & '-' & StringFormat(_Num_to_Letter($c)) & StringFormat(_Num_to_Letter($d))
FileWriteLine(@ScriptDir & '\mac.txt', $MAC)
Next
Next
Next
Next
FileWriteLine (@ScriptDir & '\mac.txt', 'finished after ' & TimerDiff($time)/1000 & ' Seconds.')
Func _Num_to_Letter($num)
Switch $num
Case 10
Return 'A'
Case 11
Return 'B'
Case 12
Return 'C'
Case 13
Return 'D'
Case 14
Return 'E'
Case 15
Return 'F'
Case Else
Return $num
EndSwitch
EndFunc
i3 2G内存的机器, 运行时间需要时间近 28秒了.
求速率的. 强悍! 多谢user3000 指点 强悍! 多谢user3000 指点
tsys 发表于 2011-12-25 13:51 http://www.autoitx.com/images/common/back.gif
这是最基本的循环和字符串运用罢了.
希望也多加油, 早点自如运用此类语句. i3 2G内存的机器, 运行时间需要时间近 28秒了.
求速率的.
user3000 发表于 2011-12-25 13:34 http://www.autoitx.com/images/common/back.gif
先申明个变量 $sOut = ''
第9行改为 $sOut &= $MAC & @CRLF
第15行改为 FileWrite(@ScriptDir & '\mac.txt', $sOut & 'finished after ' & TimerDiff($time)/1000 & ' Seconds.')
试试~ 本帖最后由 tsys 于 2011-12-25 14:22 编辑
回复 5# afan Local $time = TimerInit()
Local $sOut = ''
Local $str='BC-AE-C5-BF-'
For $a = 0 To 15
For $b = 0 To 15
For $c = 0 To 15
For $d = 0 To 15
$MAC = $str & StringFormat(_Num_to_Letter($a)) & StringFormat(_Num_to_Letter($b)) & '-' & StringFormat(_Num_to_Letter($c)) & StringFormat(_Num_to_Letter($d))
$sOut &= $MAC & @CRLF
Next
Next
Next
Next
FileWrite(@ScriptDir & '\mac.txt', $sOut & 'finished after ' & TimerDiff($time)/1000 & ' Seconds.')
Func _Num_to_Letter($num)
Switch $num
Case 10
Return 'A'
Case 11
Return 'B'
Case 12
Return 'C'
Case 13
Return 'D'
Case 14
Return 'E'
Case 15
Return 'F'
Case Else
Return $num
EndSwitch
EndFunc虚拟机512内存测试,I3 CPUfinished after 5.27156887258017 Seconds. 回复 5# afan
难道说,影响速率的主要原因就是第九行的循环内的filewriteline? A版积木玩的很好,学习了 回复afan
难道说,影响速率的主要原因就是第九行的循环内的filewriteline? A版积木玩的很好, ...
tsys 发表于 2011-12-25 14:33 http://www.autoitx.com/images/common/back.gif
是的Local $time = TimerInit()
Local $aStr =
Local $sOut = ''
Local $str = 'BC-AE-C5-BF-'
For $a = 0 To 15
For $b = 0 To 15
For $c = 0 To 15
For $d = 0 To 15
$sOut &= $str & $aStr[$a] & $aStr[$b] & '-' & $aStr[$c] & $aStr[$d] & @CRLF
Next
Next
Next
Next
FileWrite(@ScriptDir & '\macss.txt', $sOut & 'finished after ' & TimerDiff($time) / 1000 & ' Seconds.') 'finished after 3.0854824550937 Seconds."
确实如此, A版酷! 回复 9# user3000
8#还可以再快10倍左右~ WOW 代码又简洁, 速度又快!
finished after 0.286735114017175 Seconds.
页:
[1]