30个数排除指定的数后随机生成7个数并且不重号[已解决]
本帖最后由 卫和谐 于 2010-12-13 15:41 编辑准备做个30选七的工具,目标:30个数中选择7个,可以排除指定的数,最后产生的数不能有重号。目前排除部分,写的不对,请高手帮忙!#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("福彩.七乐彩选号器V1.0_卫和谐", 300, 240, 260, 160)
Local $aNum, $out, $d, $out2
$Checkbox1 = GUICtrlCreateCheckbox("", 10, 8, 20, 20)
$Label1 = GUICtrlCreateLabel("排除的号码", 35, 5, 90, 20)
;GuiCtrlSetState(-1,$GUI_ONTOP)
GUICtrlSetFont(-1, 12, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x00A820)
$Input1 = GUICtrlCreateInput("", 90, 36, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 130, 36, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("", 170, 36, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input4 = GUICtrlCreateInput("", 210, 36, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input5 = GUICtrlCreateInput("", 250, 36, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input21 = GUICtrlCreateInput("", 90, 66, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input22 = GUICtrlCreateInput("", 130, 66, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input23 = GUICtrlCreateInput("", 170, 66, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input24 = GUICtrlCreateInput("", 210, 66, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input25 = GUICtrlCreateInput("", 250, 66, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input31 = GUICtrlCreateInput("", 90, 96, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input32 = GUICtrlCreateInput("", 130, 96, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input33 = GUICtrlCreateInput("", 170, 96, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input34 = GUICtrlCreateInput("", 210, 96, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input35 = GUICtrlCreateInput("", 250, 96, 25, 25, $ES_NUMBER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("七乐彩=======选号结果=======七乐彩", 10, 135, 290, 16)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$out = GUICtrlCreateInput("", 50, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 80, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 110, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 140, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 170, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 200, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$out = GUICtrlCreateInput("", 230, 160, 28, 30, $ES_NUMBER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff0000)
$Button1 = GUICtrlCreateButton("开始", 40, 200, 97, 33, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("停止", 170, 200, 97, 33, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Quit()
Case $Button1
While 1
$x1 = Execute(GUICtrlRead($Checkbox1)) ;执行一个表达式(主要用于数学求值).
$s1 = Execute(GUICtrlRead($Input1))
$s2 = Execute(GUICtrlRead($Input2))
$s3 = Execute(GUICtrlRead($Input3))
$s4 = Execute(GUICtrlRead($Input4))
$s5 = Execute(GUICtrlRead($Input5))
$s21 = Execute(GUICtrlRead($Input21))
$s22 = Execute(GUICtrlRead($Input22))
$s23 = Execute(GUICtrlRead($Input23))
$s24 = Execute(GUICtrlRead($Input24))
$s25 = Execute(GUICtrlRead($Input25))
$s31 = Execute(GUICtrlRead($Input31))
$s32 = Execute(GUICtrlRead($Input32))
$s33 = Execute(GUICtrlRead($Input33))
$s34 = Execute(GUICtrlRead($Input34))
$s35 = Execute(GUICtrlRead($Input35))
If $x1 = 1 Then ;选择“排除的数”执行下面的循环
;For $i = 0 To 6
For $i = 0 To 6
$out[$i] = Random(1, 30, 1)
While $out[$i] = $s1 Or $out[$i] = $s2 Or $out[$i] = $s3 Or $out[$i] = $s4 Or $out[$i] = $s5 Or $out[$i] = $s21 Or $out[$i] = $s22 Or $out[$i] = $s23 Or $out[$i] = $s24 Or $out[$i] = $s25 Or $out[$i] = $s31 Or $out[$i] = $s32 Or $out[$i] = $s33 Or $out[$i] = $s34 Or $out[$i] = $s35
$out[$i] = Random(1, 30, 1)
;MsgBox(32, "123456", $out[$i])
WEnd
GUICtrlSetData($out[$i], $out[$i])
Next
;Next
Else
For $i = 0 To 29 ;-- 赋初值
$aNum[$i] = $i + 1
Next
For $i = 0 To 28 ;-- 重新排列
$r = Random($i, 29, 1)
$temp = $aNum[$i] ;-- 交换值
;MsgBox(32,"$aNum[$i]",$aNum[$i])
$aNum[$i] = $aNum[$r]
$aNum[$r] = $temp
Next
For $i = 0 To 6
GUICtrlSetData($out[$i], $aNum[$i])
Next
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button2 ;按下“停止”按钮死循环停止
ExitLoop
EndSwitch
WEnd
EndSwitch
WEnd
Func Quit()
GUISetState(@SW_HIDE)
; DllCall($Dll, "int:cdecl", "DeInitDecoration")
; DllCall($Dll, "int:cdecl", "RemoveSkin")
; DllClose($Dll)
; FileDelete(@TempDir & "\SkinCrafterDll.dll");退出后删除
; FileDelete(@TempDir & "\Zondar.skf")
Exit
EndFunc ;==>Quit 什么叫只选择排除的数 回复 2# netegg
意思是选中排除的数前面的单选框{:face (229):} 本帖最后由 netegg 于 2010-12-11 09:48 编辑
回复 3# 卫和谐
是不是选取一个数但不是指定数?给个例子说明吧 本帖最后由 3mile 于 2010-12-11 10:14 编辑
同楼上,不但不理解程序表达的意思,而且完全不理解这种彩票的意思。
只是猜测,大概是30随机选7,但可以设置排除的数字?以下只是算法,没有GUI
#include <array.au3>
Local $array
For $i = 0 To 29;定义二维数组,第二列作为排除BOOL
$array[$i] = $i + 1
$array[$i] = False
Next
Local $del_number='25,22,30';假定25,22,30要排除掉
$del_number=StringSplit($del_number,',')
For $i=1 To $del_number
$array)-1]=True
Next
Local $str=''
For $n=0 To 6;输出结果
$random=Random(0,29,1)
If $array[$random]=True Then
$n-=1
Else
$str&=$array[$random]&@TAB
EndIf
Next
MsgBox(0,0,$str) 回复 5# 3mile
是这个意思,难道我没说明白?
30随机选7,但可以设置排除的数字 不过,30随机选7,这7个数还不能重复,但可以设置排除的数字,最好在我的例子上改,我的例子不知道别在哪里了,排除这部分搞不定!! 回复 7# 卫和谐
你的GUI内控件太多,看着头晕。
还是同5楼代码,只有算法,增加了一行,7个数字不重复。
#include <array.au3>
Local $array
For $i = 0 To 29;定义二维数组,第二列作为排除BOOL
$array[$i] = $i + 1
$array[$i] = False
Next
Local $del_number='25,22,30';假定25,22,30要排除掉
$del_number=StringSplit($del_number,',')
For $i=1 To $del_number
$array)-1]=True
Next
Local $str=''
For $n=0 To 6;输出结果
$random=Random(0,29,1)
If $array[$random]=True Then
$n-=1
Else
$str&=$array[$random]&@TAB
$array[$random]=True
EndIf
Next
MsgBox(0,0,$str)
回复 8# 3mile
没看明白,惭愧! #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$Form1 = GUICreate("Form1", 368, 190, 246, 179)
GUICtrlCreateLabel("排除的数字,英文逗号隔开,没有则留空:", 8, 16, 250, 17)
$Input = GUICtrlCreateInput("", 8, 40, 320, 21)
$Input0 = GUICtrlCreateInput("", 16, 134, 41, 21)
$Input1 =GUICtrlCreateInput("", 67, 134, 41, 21)
$Input2 =GUICtrlCreateInput("", 115, 134, 41, 21)
$Input3 =GUICtrlCreateInput("", 163, 134, 41, 21)
$Input4 =GUICtrlCreateInput("", 211, 134, 41, 21)
$Input5 =GUICtrlCreateInput("", 259, 134, 41, 21)
$Input6 =GUICtrlCreateInput("", 307, 134, 41, 21)
$Button1 = GUICtrlCreateButton("开始", 88, 88, 75, 25)
$Button2 = GUICtrlCreateButton("停止", 200, 88, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If GUICtrlRead($Input) <> "" Then
$a = StringSplit(GUICtrlRead($Input), ",")
Else
Local $a =
EndIf
While 1
Local $b
For $i = 0 To 6
While 1
$Num = Random(1, 30, 1)
If _ArraySearch($b, $Num, 0, 0) = -1 And_ArraySearch($a, $Num) = -1 Then
$b[$i] = $Num
GUICtrlSetData(Eval("Input" & $i), $Num)
ExitLoop
EndIf
WEnd
Next
If GUIGetMsg() = $Button2 Then ExitLoop
WEnd
EndSwitch
WEnd
= = 好神奇的例子 百位个位十位都是神马... 不是1-30么 难道是每一栏都能选排除的数? 回复 5# 3mile
试过了,但是随机产生的数有重复的! 在随机取值的那一段
Local $i_out;排除的6个数,这里仅为示例,实际操作时自己取值
For $i = 0 To 29 ;-- 赋初值
If $i = $i_out Or $i = $i_out Or $i = $i_out Or $i = $i_out Or $i = $i_out Or $i = $i_out Then ContinueLoop ;如果等于要排除的数值则跳过
$aNum[$i] = $i + 1
Next
同样在下一个循环
For $i = 0 To 28 ;-- 重新排列
插入要排除的数值.
思路就是这样,自己调试下吧 其实要在LZ的代码上改也不难,但是我实在没法理解明明是1到30,LZ要排除的数什么会有 百位数,十位数,个位数。这点LZ能解释让我明白了才好改
如果仅仅是为了排除1-30中的任意几个数,我在10#的代码都可以解决了 回复 14# yhxhappy
谢谢了 你的代码不错!
页:
[1]
2