• Want to help us with this year's BoS Trials?
    Let us know before 30 June. See this thread for details
  • Looking for HSC notes and resources?
    Check out our Notes & Resources page

Random Fuctions in .net (1 Viewer)

raging_squid

Member
Joined
Jun 11, 2004
Messages
36
Gender
Male
HSC
2005
how does the random function work in .net and wat are the different ways of using it. I am making a scissors paper rock game and i need the img List to display a random picture (scissors, paper or rock) at the moment it only display 2 different pictures and not 3. I am displaying the outcome in a label. How can i correct this?
below is wat i have so far
Code:
     Private Sub BtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOk.Click
        Static WhichPos As Integer = 0
        lblOutcome.Image = imlOutcome.Images(WhichPos)
        WhichPos += 1
        WhichPos = WhichPos Mod 3
        WhichPos = Int(Rnd(1 - 3)) + 1
    End Sub
 
Joined
May 27, 2004
Messages
107
Gender
Male
HSC
2004
why do u have INT(RND(1 - 3)) +1

u should try INT(RND(3-1)) + 1

cause that produces a random number 3 and one... im not entirly sure but try...
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Dude... you're using legacy functions which are not natively .NET in respect, they are legacy functions from VB6 the new Random function is by instantiating a new instance of the Random class within the System. namespace, here is how you do it:

Dim randomiser As New System.Random
Dim randomisedIntVal As Integer
randomisedIntVal = randomiser.Next()

The .Next() method is an overloaded method, with 3 different constructors, one of which allows you to specify a range to randomise the integer in. Hope this helps.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top