Sign in to follow this  
Kaczor_90

Visual Basic Random number

Recommended Posts

Kaczor_90    100
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
Aardvajk    13207
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this