hi
I'm doing a project at the moment for school,I need to randomly pick a number from an array,which I can do but I can only use that number three times,I dont want an answer just a few hints please
thanks
Printable View
hi
I'm doing a project at the moment for school,I need to randomly pick a number from an array,which I can do but I can only use that number three times,I dont want an answer just a few hints please
thanks
why dont you start playing with random number?
what he said....
http://msdn.microsoft.com/en-us/libr...em.random.aspx
I understand the random function,I just dont know how to keep count of which element of the array I already used
Why not use another array(or List collection) to store the indices that you already used from the first array. So every time you use an element from the first array, store that integer index into the 2nd array. Then when you go to grab a value from the first array check this 2nd array to see if you have already looked at that index.
I have a modified black jack game to create,which deals two cards to the dealer and the player,The value of the cards are stored in an array,which are 1 to 11,I can only use each card 4 times,how do i keep count of which card i have already used,i tried using two arrays but getting nowhere
Write a class for the cards, with properties Number and TimesCalled. Create a list of the cards, and then you can just do something like this...
vb Code:
Dim C As Card = Cards(5) If C.TimesCalled < 4 Then C.Call() C.TimesCalled +=1 Else GetAnotherCard() End If
Thanks for the reply,i havent done classes in school yet so im going to have to do it another way,im randomly picking two card values each for the player and the computer and adding them together to give the total of the first hand,so im going to have to keep count of them first
Code:Dim deck() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
Dim deck2(10) As Integer
Dim dtotal As Integer
Dim ptotal As Integer
Dim num As Integer
Dim num2 As Integer
Dim num3 As Integer
Dim num4 As Integer
Dim dh As Integer
Dim dh2 As Integer
Dim ph As Integer
Dim ph2 As Integer
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
num = Int(Rnd() * (10) + 1)
num2 = Int(Rnd() * (10) + 1)
num3 = Int(Rnd() * (10) + 1)
num4 = Int(Rnd() * (10) + 1)
dh = deck(num)
dh2 = deck(num2)
ph = deck(num3)
ph2 = deck(num4)
dtotal = dh + dh2
ptotal = ph + dh2
txtdealer.Text = CStr(dtotal)
txtplayer.Text = CStr(ptotal)
End Sub
End Class
Have you done structures yet? If so use that concept as they are like a less sophisticated class. Also the way you are trying to create random numbers is not correct/appropriate in VB.Net. Don't use Randomize() or Rnd. Use the Random class like this:
vb Code:
Dim rnd As New Random() Dim Random As Integer = rnd.Next()