RobertoFreemano
asked on
Random Number Gen with no duplicates - vb.net
Hi Experts,
I'm trying to build a simple number generator (winform) app VB-Express 2010.
************************** ********** ********** *
** Label1 Label2 Label3 Label4 Label5 Label6 **
** **
** BUTTON1 **
************************** ********** ******
Click Button 1, all labels will generate numbers between 1, 6
- thias works great.
But, I want to prevent duplicate PLEASE!
Roberto (novice)
I'm trying to build a simple number generator (winform) app VB-Express 2010.
**************************
** Label1 Label2 Label3 Label4 Label5 Label6 **
** **
** BUTTON1 **
**************************
Click Button 1, all labels will generate numbers between 1, 6
- thias works great.
But, I want to prevent duplicate PLEASE!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Dim objRandom As New System.Random( _
CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))
Public Function GetRandomNumber( _
Optional ByVal Low As Integer = 1, _
Optional ByVal High As Integer = 100) As Integer
' Returns a random number,
' between the optional Low and High parameters
Return objRandom.Next(Low, High + 1)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intDiceRoll1 As Integer
Dim intDiceRoll2 As Integer
Dim intDiceRoll3 As Integer
Dim intDiceRoll4 As Integer
Dim intDiceRoll5 As Integer
Dim intDiceRoll6 As Integer
intDiceRoll1 = GetRandomNumber(1, 6)
intDiceRoll2 = GetRandomNumber(1, 6)
intDiceRoll3 = GetRandomNumber(1, 6)
intDiceRoll4 = GetRandomNumber(1, 6)
intDiceRoll5 = GetRandomNumber(1, 6)
intDiceRoll6 = GetRandomNumber(1, 6)
Label1.Text = (intDiceRoll1.ToString)
Label2.Text = (intDiceRoll2.ToString)
Label3.Text = (intDiceRoll3.ToString)
Label4.Text = (intDiceRoll4.ToString)
Label5.Text = (intDiceRoll5.ToString)
Label6.Text = (intDiceRoll6.ToString)
End Sub
Thanks,Roberto (novice)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi AW, I'll try your code - thanks ;)
You should probably set the numberOfTimesToShuffle variable to a value like 10. This is like the number of times you would shuffle a real deck of cards. When you really shuffle a deck of cards, you NEVER simply shuffle 1 or 2 times.
AW
AW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Guys ;)
Idle_Mind's solution just worked...
AW = wasn't sure how to connect this up to textbox
CC = Thanks for input
;)
Idle_Mind's solution just worked...
AW = wasn't sure how to connect this up to textbox
CC = Thanks for input
;)
ASKER
How do I do this pls?
Roberto