Jump to content
  • Advertisement
Sign in to follow this  

Visual Basic Random number

This topic is 2941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. Recently playing in the VB and I have a problem with the lottery numbers. Namely, that they were drawn from a range of pressing the button. Here's the code that already have: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label9.Visible = False Label2.Visible = True Label3.Text = CStr(Int(Rnd() * 100)) Label4.Text = CStr(Int(Rnd() * 100)) Label5.Text = CStr(Int(Rnd() * 100)) Label6.Text = CStr(Int(Rnd() * 100)) Label7.Text = CStr(Int(Rnd() * 100)) Label8.Text = CStr(Int(Rnd() * 100)) End Sub End Class And my point is here that the figures were drawn from a specific range. Let's say from 1 to 21. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Not sure I fully understand the question, and I can't help on the VB, but lottery numbers are drawn uniquely from a range, not just a list of random numbers.

For example, to generate the equivalent of lottery numbers from the range 1-21, I'd create an array of the full 21 numbers, randomly shuffle the array, then return the first six numbers in the array.

The best form of random shuffle I know is to iterate over the array in order and for each item, select a random index and swap the current item with that index.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!