小豪 10 發表於 May 13, 2005 檢舉 Share 發表於 May 13, 2005 有沒有辦法讓VB的RND函數給他設定一個範圍然後從這範圍不重複且都要取到有辦法這樣嗎? 鏈接文章 分享到其他網站
jimmykuo 10 發表於 May 13, 2005 檢舉 Share 發表於 May 13, 2005 不太懂你的意思rnd是取0-1之間的數這之間有無限多個如果要取整數可以用int這個函數如果要0~10之間那就成與他的倍數就照下面這樣打int(rnd*10)這樣就有亂數種數出現了至於不要重複那就用if的判斷式吧 鏈接文章 分享到其他網站
小豪 10 發表於 May 14, 2005 作者 檢舉 Share 發表於 May 14, 2005 我再說一次好了假設我現在指定要取1~10我能命令他任意給我一個1~10(不能重複)的數列嗎EX第一次是1 5 3 7 4 2 6 8 9 10 第二次是 2 5 4 6 1 3 7 9 10 8 第三次是 7 8 1 5 6 3 2 4 10 9......等等 鏈接文章 分享到其他網站
jimmykuo 10 發表於 May 14, 2005 檢舉 Share 發表於 May 14, 2005 我的想法是先把亂數放成數列如for i =1 to 10把亂數變成(i,亂數)在用if 亂數一樣 then goto再從跑一次不過我沒有辦法給你詳細的程式碼因為真的要打出來要想一下@@" 鏈接文章 分享到其他網站
imprazaguy 10 發表於 May 14, 2005 檢舉 Share 發表於 May 14, 2005 假如數字不多的話,例如1∼10。我想你可以把它宣告一個陣列,利用亂數來對調陣列的值,重複做的數十次或數百次,這樣就可以達到隨機分佈的效果了。 鏈接文章 分享到其他網站
電腦狂 10 發表於 May 14, 2005 檢舉 Share 發表於 May 14, 2005 已樂透為範例如果是42取6不重複最基本的就是這樣了物件:command *1textbox*6Private Sub Command1_Click()Dim a(42) As Integer,open1 As Integer,i As Integer,j As IntegerDim change1 As Integer,c As String,l As Integer,d As IntegerFor j = 1 To 42a(j) = jNext j d = 41 For i = 0 To 5 Randomize d = d - i c = Rnd * d + 1 open1 = a(Int©) l = 42 - i change1 = a(l) a(l) = open1 a(open1) = change1 Text1(i).Text = a(l) Next iEnd Sub 鏈接文章 分享到其他網站
knsman78 10 發表於 May 15, 2005 檢舉 Share 發表於 May 15, 2005 上面的大大~~有這麼麻煩嗎VB.NET: Dim a(7), b, c As Byte Randomize() a(0) = Int(49 * Rnd()) + 1 For b = 1 To 6 a(b) = Int(49 * Rnd()) + 1 For c = 0 To b - 1 If a(b) = a© Then b -= 1 End If Next Next這是我之前慢慢想寫出來的>.<"a我不知道其他版本的可不可以用 鏈接文章 分享到其他網站
ckmarkhsu 7 發表於 May 16, 2005 檢舉 Share 發表於 May 16, 2005 最初由 knsman78 發表上面的大大~~有這麼麻煩嗎VB.NET: Dim a(7), b, c As Byte Randomize() a(0) = Int(49 * Rnd()) + 1 For b = 1 To 6 a(b) = Int(49 * Rnd()) + 1 .............(論壇訊息:引文過長 恕刪) 大家可以用 php標籤 這樣就可以維持code的排版:)你那是VB.net的語法vb6不支援 -= :P 鏈接文章 分享到其他網站
martin77813 10 發表於 May 22, 2005 檢舉 Share 發表於 May 22, 2005 最初由 小豪 發表我再說一次好了假設我現在指定要取1~10我能命令他任意給我一個1~10(不能重複)的數列嗎EX第一次是1 5 3 7 4 2 6 8 9 10 第二次是 2 5 4 6 1 3 7 9 10 8 第三次是 7 8 1 5 6 3 2 4 10 9......?............(論壇訊息:引文過長 恕刪) 就用do...loop跑~然後每跑一個值就跟陣列tmp()用if...then比對tmp裡面裝的是以跑出的數字如果沒有就儲存~有的話就不要儲存~~再跑一次until的限制就設為當ubound(tmp)=所要的數字範圍的字數-1降應該就好了吧... 鏈接文章 分享到其他網站
蟲ˇ 17 發表於 May 24, 2005 檢舉 Share 發表於 May 24, 2005 最初由 非人 發表加一段判別式 和一個參數 我不會寫....拜託 非人大大寫一下八 鏈接文章 分享到其他網站
ckguozhi 10 發表於 May 27, 2005 檢舉 Share 發表於 May 27, 2005 最初由 電腦狂 發表已樂透為範例如果是42取6不重複最基本的就是這樣了物件:command *1textbox*6Private Sub Command1_Click()Dim a(42) As Integer,open1 As Integer,i As Integer,j As IntegerDim change1 As Integer,c .............(論壇訊息:引文過長 恕刪) 你的程式...顯示的部份好像有問題實際跑過了還是會重複存來存去的陣列....看不太懂 鏈接文章 分享到其他網站
ckguozhi 10 發表於 May 27, 2005 檢舉 Share 發表於 May 27, 2005 自己寫了一個物件:Command1,Text1 Private Sub Command1_Click()Dim num, i, j, certain(5) As IntegerLabel1 = ""Randomize TimerFor i = 0 To 5rechoose: certain(i) = Int(Rnd * 42) + 1 For j = 0 To i -1 If certain(i) = certain(j) Then GoTo rechoose End If Next j Text1 = Text1 & " " & certain(i)Next iEnd Sub 迴圈跑了65535次確定不重複 鏈接文章 分享到其他網站
語易奇 10 發表於 May 27, 2005 檢舉 Share 發表於 May 27, 2005 試看看Private Sub Command1_Click() Randomize Timer Dim N(5) For I = 0 To 5 '亂數序列中不會有相同的數字 r = 1 Do Until r <> 1 'r = 1 表示n(i)的亂數有重覆 N(I) = Int(10 * Rnd) + 1 r = 0 For j = 0 To I - 1 If N(I) = N(j) Then r = 1 Next Loop Next Me.Cls Print N(0); N(1); N(2); N(3); N(4); N(5) End Sub 鏈接文章 分享到其他網站
ckguozhi 10 發表於 May 29, 2005 檢舉 Share 發表於 May 29, 2005 最初由 ~§碎心§~ 發表厄 還是看不懂.... 看程式有耐心慢慢看還是看不懂給它實際跑跑看吧 鏈接文章 分享到其他網站
蟲ˇ 17 發表於 June 3, 2005 檢舉 Share 發表於 June 3, 2005 那假若 要隨機取a b c d e 個亂數 在用 選擇排續法排大小 的程式要怎寫?? 鏈接文章 分享到其他網站
小豪 10 發表於 June 5, 2005 作者 檢舉 Share 發表於 June 5, 2005 這是我後來去問老師的老師給我提示我寫出來的但一直有問題耶(還是會有重複)能否請各位大大幫我看一下Private Sub Form_Activate()Dim total(1 To 52) As ByteDim play1(1 To 13) As ByteDim play2(1 To 13) As ByteDim play3(1 To 13) As ByteDim play4(1 To 13) As ByteDim a As Byte, i As Byte For i = 1 To 52 '全設一 total(i) = 1 Next i Randomize Do For i = 1 To 13 '把play1填滿 a = Fix(52 * Rnd()) + 1 If total(a) = 1 Then play1(i) = a total(a) = 0 End If Next i Loop Until play1(1) <> 0 And play1(2) <> 0 And play1(3) <> 0 And play1(4) <> 0 And play1(5) <> 0 And play1(6) <> 0 And play1(7) <> 0 And play1(8) <> 0 And play1(9) <> 0 And play1(10) <> 0 And play1(11) <> 0 And play1(12) <> 0 And play1(13) '檢查是否填滿 Do For i = 1 To 52 '重設 total(i) = 1 Next i For i = 1 To 13 If total(play1(i)) = 1 Then '消去play1 total(play1(i)) = 0 End If Next i For i = 1 To 13 '把play2填滿 a = Fix(52 * Rnd()) + 1 If total(a) = 1 Then play2(i) = a total(a) = 0 End If Next i Loop Until play2(1) <> 0 And play2(2) <> 0 And play2(3) <> 0 And play2(4) <> 0 And play2(5) <> 0 And play2(6) <> 0 And play2(7) <> 0 And play2(8) <> 0 And play2(9) <> 0 And play2(10) <> 0 And play2(11) <> 0 And play2(12) <> 0 And play2(13) '檢查是否填滿 Do For i = 1 To 52 '重設 total(i) = 1 Next i For i = 1 To 13 If total(play1(i)) = 1 Then '消去play1 total(play1(i)) = 0 End If Next i For i = 1 To 13 If total(play2(i)) = 1 Then '消去play2 total(play2(i)) = 0 End If Next i For i = 1 To 13 '把play3填滿 a = Fix(52 * Rnd()) + 1 If total(a) = 1 Then play3(i) = a total(a) = 0 End If Next i Loop Until play3(1) <> 0 And play3(2) <> 0 And play3(3) <> 0 And play3(4) <> 0 And play3(5) <> 0 And play3(6) <> 0 And play3(7) <> 0 And play3(8) <> 0 And play3(9) <> 0 And play3(10) <> 0 And play3(11) <> 0 And play3(12) <> 0 And play3(13) '檢查是否填滿 Do For i = 1 To 52 total(i) = 1 Next i For i = 1 To 13 '消去play1 If total(play1(i)) = 1 Then total(play1(i)) = 0 End If Next i For i = 1 To 13 '消去play2 If total(play2(i)) = 1 Then total(play2(i)) = 0 End If Next i For i = 1 To 13 '消去play3 If total(play3(i)) = 1 Then total(play3(i)) = 0 End If Next i For i = 1 To 13 '把play4填滿 a = Fix(52 * Rnd()) + 1 If total(a) = 1 Then play4(i) = a total(a) = 0 End If Next i Loop Until play4(1) <> 0 And play4(2) <> 0 And play4(3) <> 0 And play4(4) <> 0 And play4(5) <> 0 And play4(6) <> 0 And play4(7) <> 0 And play4(8) <> 0 And play4(9) <> 0 And play4(10) <> 0 And play4(11) <> 0 And play4(12) <> 0 And play4(13) '檢查是否填滿 鏈接文章 分享到其他網站
語易奇 10 發表於 June 5, 2005 檢舉 Share 發表於 June 5, 2005 嗯? 有需要寫到那麼長嗎...= =||||||| 好亂...都沒縮排...= =||||||| 懶得看... 鏈接文章 分享到其他網站
千年一嘆 10 發表於 June 16, 2005 檢舉 Share 發表於 June 16, 2005 呃,建中某位老師說要用〝抽獎箱原理〞......box="1234567890"RandomizeFor i =10 To 6 Step -1 r=Int(1+Rnd()*i) word=word+Space(2)+Mid(box, r, 1) box=Left(box, r-1)+Right(box, i-r)Next i 鏈接文章 分享到其他網站
tmp_i_p 10 發表於 June 30, 2005 檢舉 Share 發表於 June 30, 2005 dim str,i,tmp,ansstr="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"randomizefor i=1 to 20 tmp=mid(str,int(len(str)*rnd+1),1) ans=ans & tmp str=replace(str,tmp,"") nextmsgbox ans這是個取20個亂數字原來組成字串的程式 鏈接文章 分享到其他網站
tmp_i_p 10 發表於 June 30, 2005 檢舉 Share 發表於 June 30, 2005 dim str,i,tmp,ansstr="0123456789abcdefghijklmnopqrstuvwxyz"randomizefor i=1 to 20 tmp=mid(str,int(len(str)*rnd+1),1) ans=ans & tmp str=replace(str,tmp,"") nextmsgbox ans 鏈接文章 分享到其他網站
Recommended Posts
請登入後來留意見
在登入之後,您才能留意見
立即登入