2013-12-16 181 views
0

我做了一個簡單的程序,生成隨機RGB值,但我不知道如何計算所有可能的RGB代碼組合&可能儘快生成它們,任何人都可以幫助我嗎?代碼計算所有可能的組合[RGB]

計算部分:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    r1 = CInt(Int((255 * Rnd()) + 0)) 
    g1 = CInt(Int((255 * Rnd()) + 0)) 
    b1 = CInt(Int((255 * Rnd()) + 0)) 
    If ListBox1.Items.Contains(r1 & "," & g1 & "," & b1) Then 
     'number is clone of any number in Listbox1.items 
     Label2.Text = Label2.Text + 1 
    Else 
     ListBox1.Items.Add(r1 & "," & g1 & "," & b1) 
     Label1.Text = ListBox1.Items.Count.ToString 
    End If 
End Sub 
+0

如果你想把所有的組合(按隨機順序),那麼你應該尋找生成完整集非隨機,然後*洗牌*他們。 –

+0

@Damien_The_Unbeliever你是什麼意思? –

+0

[鏈接](http://prntscr.com/2bjnhm)程序的屏幕在這裏 –

回答

0

工作不夠;)

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    r1 = CInt(Int((255 * Rnd()) + 0)) 
    g1 = CInt(Int((255 * Rnd()) + 0)) 
    b1 = CInt(Int((255 * Rnd()) + 0)) 
    If ListBox1.Items.Contains(r1 & "," & g1 & "," & b1) Then 
     'number is clone of any number in Listbox1.items 
     Label2.Text = Label2.Text + 1 
    Else 
     ListBox1.Items.Add(r1 & "," & g1 & "," & b1) 
     Label1.Text = ListBox1.Items.Count.ToString 
    End If 
End Sub