找回密码
 加入
搜索
查看: 6056|回复: 10

[效率算法] 乱序问题(已解决)

  [复制链接]
发表于 2010-10-17 11:19:21 | 显示全部楼层 |阅读模式
本帖最后由 shano 于 2010-10-18 06:54 编辑

想生成一组14位的字符串
包含数字大写小写  不知道如何打乱顺序



$txt = ""

$usern1 = ""
for $u = 1 to 4 ;生成4个小写字母
$usern1 = $usern1&Chr (Random (97,122, 1 ))
Next
$usern2 = ""
for $u = 1 to 5 ;生成5个数字
$usern2 = $usern2&Random (0,9,1)
Next
$usern3 = ""
for $u = 1 to 5;生成5个大写字母
$usern3 = $usern3&Chr(Random(65,90,1))
Next   
$txt = $usern1&$usern2&$usern3

MsgBox(0,0,$txt)
发表于 2010-10-17 12:13:00 | 显示全部楼层
你这段代码不是可以生成你要求的那样吗?
如:aaaa12345BBBBB,前4位小写,中5位数字,后5位大写。
你的意思是完全乱序?还是有规律的乱序?
EXAMPLE1()

Example2()

Func EXAMPLE1()
Local $output=''
While 1
    If StringLen($output) > 13 Then ExitLoop
    $number = StringLen($output)
    Select
        Case $number < 4
            $output &= Chr (Random (97,122, 1 ))    
        Case $number < 9
            $output &= Random (0,9,1)
        Case $number < 14
            $output &= Chr(Random(65,90,1))
    EndSelect
WEnd
MsgBox(0,'有规律',$output)
EndFunc

Func EXAMPLE2()
    Local $output
    While 1
        If StringLen($output) > 13 Then ExitLoop
        $random=Random(48,122,1)
        Select
            Case $random>57 And $random <63
                ContinueLoop
            Case $random>90 And $random<97
                ContinueLoop
        EndSelect
        $output&=Chr($random)
    WEnd
MsgBox(0,'完全乱序',$output)
EndFunc

评分

参与人数 1金钱 +30 收起 理由
水木子 + 30 3G果然厉害!学习啦!

查看全部评分

发表于 2010-10-17 12:59:24 | 显示全部楼层
我是做的12个字符,你看看是不是这样?

#include <Array.au3>
;随时生成十进制数
$iN1 = Random(0, 9, 1)
$iN2 = Random(0, 9, 1)
$iN3 = Random(0, 9, 1)
$iN4 = Random(0, 9, 1)

;随机生成大写字母
$sC1 = Chr(Random(65, 90, 1))
$sC2 = Chr(Random(65, 90, 1))
$sC3 = Chr(Random(65, 90, 1))
$sC4 = Chr(Random(65, 90, 1))

;随机生成小写字母
$sL1 = Chr(Random(97, 122, 1))
$sL2 = Chr(Random(97, 122, 1))
$sL3 = Chr(Random(97, 122, 1))
$sL4 = Chr(Random(97, 122, 1))

Local $sText
Local $aArray[12] = [$iN1, $iN2, $iN3, $iN4, $sC1, $sC2, $sC3, $sC4, $sL1, $sL2, $sL3, $sL4]

For $i = 12 To 1 Step -1
        $iNumber = Random(1, $i - 1, 1)
        $sText &= $aArray[$iNumber] & '  '
        _ArrayDelete($aArray, $iNumber)
Next

MsgBox(0, '乱序结果', $sText)

评分

参与人数 2金钱 +50 收起 理由
3mile + 20 殊途同归啊
afan + 30

查看全部评分

发表于 2010-10-17 13:36:03 | 显示全部楼层
水版就是厉害哈,学习了先
发表于 2010-10-18 06:03:29 | 显示全部楼层
本帖最后由 foboy 于 2010-10-18 06:05 编辑

以下是我做过的一个生成卡号的东西,可以生成指定数量、指定长度、指定前缀的字符。可以选择“数字”、“大写字母”、“小写字母”中的任意组合。
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=..\woniu.ico
#AutoIt3Wrapper_outfile=编译成品\卡号生成器.exe
#AutoIt3Wrapper_Res_Comment=卡号生成器 猛牛脚本 HTTP://MENGNIU.IN QQ:114026307
#AutoIt3Wrapper_Res_Description=卡号生成器 猛牛脚本 HTTP://MENGNIU.IN
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=MENGNIU.IN 猛牛脚本
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $user_pre, $user_len, $user_num, $user_option[3]
Global $Checkbox_str[3]
Global $sysfile = @ScriptDir & "\mengniu.in"
Global $file_log
Global $string_rang[3][2] = [[48, 57],[97, 122],[65, 90]]
$user_pre = IniRead($sysfile, "设置", "前缀", "")
$user_len = IniRead($sysfile, "设置", "长度", 5)
$user_num = IniRead($sysfile, "设置", "数量", 10)
$checkit = 0
For $g_i = 0 To 2
        $user_option[$g_i] = IniRead($sysfile, "设置", "选项" & $g_i, 0)
        If $user_option[$g_i] == 1 Then $checkit = 1
Next
If $checkit == 0 Then $user_option[0] = 1
DirCreate("生成记录")
#Region ### START Koda GUI section ### Form=D:\程序\AUTOIT\SciTe\Koda\Forms\卡号生成.kxf
$Form1 = GUICreate("卡号生成器", 384, 201, 250, 435)
GUISetOnEvent($GUI_EVENT_CLOSE, "tuichu")
$Group1 = GUICtrlCreateGroup("点卡生成", 8, 8, 369, 169)
$Group2 = GUICtrlCreateGroup("生成设置", 16, 23, 161, 145)
$Label1 = GUICtrlCreateLabel("卡号前缀:", 24, 40, 64, 17)
$Input_card_pre = GUICtrlCreateInput($user_pre, 88, 36, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetOnEvent(-1, "_mygui")
$Label2 = GUICtrlCreateLabel("附加长度:", 24, 64, 64, 17, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
$Input_len = GUICtrlCreateInput($user_len, 88, 60, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetOnEvent(-1, "_mygui")
$Checkbox_str[0] = GUICtrlCreateCheckbox("数字", 24, 112, 49, 17)
If $user_option[0] == 1 Then GUICtrlSetState(-1, $gui_checked)
GUICtrlSetOnEvent(-1, "_selectstr")
$Checkbox_str[1] = GUICtrlCreateCheckbox("小写", 72, 112, 41, 17)
GUICtrlSetOnEvent(-1, "_selectstr")
If $user_option[1] == 1 Then GUICtrlSetState(-1, $gui_checked)
$Checkbox_str[2] = GUICtrlCreateCheckbox("大写", 118, 112, 46, 17)
GUICtrlSetOnEvent(-1, "_selectstr")
If $user_option[2] == 1 Then GUICtrlSetState(-1, $gui_checked)
$Label3 = GUICtrlCreateLabel("生成数量:", 24, 88, 64, 17)
$Input_num = GUICtrlCreateInput($user_num, 88, 84, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
GUICtrlSetOnEvent(-1, "_mygui")
$Button_begin = GUICtrlCreateButton("生成", 24, 136, 59, 22)
GUICtrlSetOnEvent(-1, "_do_nums")
$Button_open = GUICtrlCreateButton("打开文件", 101, 136, 59, 22)
GUICtrlSetOnEvent(-1, "_mygui")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit_cards = GUICtrlCreateEdit("", 184, 24, 185, 145)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label_now_opr = GUICtrlCreateLabel("", 8, 182, 364, 17)
GUICtrlSetColor(-1, 0x008000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(100)
WEnd
Func _mygui()
        Switch @GUI_CtrlId
                Case $Input_card_pre
                        $user_pre = GUICtrlRead($Input_card_pre)
                        IniWrite($sysfile, "设置", "前缀", $user_pre)
                        _set_now_opr("已修改前缀为:" & $user_pre)
                Case $Input_len
                        $user_len = GUICtrlRead($Input_len)
                        IniWrite($sysfile, "设置", "长度", $user_len)
                        _set_now_opr("已修改长度为:" & $user_len)
                Case $Input_num
                        $user_num = GUICtrlRead($Input_num)
                        IniWrite($sysfile, "设置", "数量", $user_num)
                        _set_now_opr("已修改数量为:" & $user_num)
                Case $Button_open
                        ShellExecute($file_log)
        EndSwitch
EndFunc   ;==>_mygui
Func _selectstr()
        $checkit = 0
        For $_i = 0 To 2
                $user_option[$_i] = GUICtrlRead($Checkbox_str[$_i])
                IniWrite($sysfile, "设置", "选项" & $_i, $user_option[$_i])
                If $user_option[$_i] == 1 Then $checkit = 1
        Next
        If $checkit == 0 Then
                _set_now_opr("不选任何项,会自动选则数字。")
                $user_option[0] = 1
        EndIf
EndFunc   ;==>_selectstr
Func _set_now_opr($_content)
        If GUICtrlRead($Label_now_opr) <> $_content Then GUICtrlSetData($Label_now_opr, $_content)
EndFunc   ;==>_set_now_opr
Func _do_nums()
        Local $_the_strings = "", $_ids, $_all_card = "", $_len_old
        $_len_old = StringLen($user_pre) + $user_len
        For $_i = 1 To $user_num
                $_the_strings = $user_pre
                Do
                        $_ids = Random(0, 2, 1)
                        If $user_option[$_ids] <> 1 Then ContinueLoop
                        $_the_strings &= Chr(Random($string_rang[$_ids][0], $string_rang[$_ids][1], 1))
                Until StringLen($_the_strings) >= $_len_old
                $_all_card &= $_the_strings & @CRLF
        Next
        _add_msg_to_edit($Edit_cards, $_all_card)
        $file_log = @ScriptDir & "\生成记录" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt"
        $filehandle = FileOpen($file_log, 9)
        FileWrite($filehandle, $_all_card)
        FileClose($filehandle)
        _set_now_opr("成功生成" & $user_num & "个卡号,已保存到文件。")
EndFunc   ;==>_do_nums
Func tuichu()
        Exit
EndFunc
Func _add_msg_to_edit($_edit_name, $_content)
        $_old_msg = GUICtrlRead($_edit_name)
        GUICtrlSetData($_edit_name, $_old_msg & $_content & @CRLF)
        GUICtrlRecvMsg($_edit_name, $EM_SCROLLCARET);滚动到插入符位置
EndFunc   ;==>_add_msg_to_edit

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +30 收起 理由
afan + 30

查看全部评分

发表于 2010-10-18 07:05:56 | 显示全部楼层
代码收藏了....
发表于 2010-10-18 08:36:17 | 显示全部楼层
呵呵,学习一下。。
发表于 2010-10-18 10:44:22 | 显示全部楼层
恩  ,不错。好东西,可是不知道作用。不过思路已经有了。
发表于 2010-10-21 08:30:38 | 显示全部楼层
都不错,都有非常强的逻辑思维。学习了哈。
发表于 2010-10-21 19:03:34 | 显示全部楼层
都是高手,学习学习
发表于 2010-10-23 09:49:33 | 显示全部楼层
大家都很牛嘛!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-21 05:18 , Processed in 0.085536 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表