?
Solved

how to get multiple random numbers

Posted on 2010-11-29
3
Medium Priority
?
407 Views
Last Modified: 2013-11-27
I am trying to write a Slot machine program for a VB2008 class and i am stuck. i need to call three different random colors from my array to make it work but they all are the same, and i'm not sure why. what can i do to make it work what code i have so far is following. Thanks in advance :)

Public Class SlotMachine

    Dim Colors As Color() = {Color.Blue, Color.Red, Color.Yellow, Color.Green, Color.Orange}
    Dim used As Boolean() = New Boolean(0 To Colors.GetUpperBound(0)) {}

    Private Sub PlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles PlayButton.Click

        Dim rand As Color

        rand = Colors(GetRandomNumber())
        SlotLabel1.BackColor = rand

        rand = Colors(GetRandomNumber())
        SlotLabel2.BackColor = rand

        rand = Colors(GetRandomNumber())
        SlotLabel3.BackColor = rand

    End Sub

    ' return an unused random number
    Function GetRandomNumber() As Integer

        Dim randomObject As Random = New Random()
        Dim randomNumber As Integer = 0 + randomObject.Next(5)

        Return randomNumber ' return index for new flag
    End Function ' GetUniqueRandomNumber

End Class
0
Comment
Question by:Stewart1206
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34235577
Change:

    Dim randomObject As Random = New Random()

To:

    Static randomObject As Random = New Random()

*This will not guarantee that they will all be different though.
0
 

Author Closing Comment

by:Stewart1206
ID: 34235606
answered it correctly on first reply :D
0
 

Author Comment

by:Stewart1206
ID: 34235608
Thank you that did it!  i'm sure i will need some more help before it's done but that problem is solved THANK YOU
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question