How to make a random number generator

Use this board to post your code snippets - tips and tricks
5 posts Page 1 of 1
Contributors
User avatar
flashsight
New Member
New Member
Posts: 19
Joined: Fri Jun 18, 2010 7:42 am

1)First, add a button from the toolbox to generate the number

2)Next, add a textbox to the form

3)Last, double click on the button and enter this code
Code: Select all
Dim rndnumber As Random
        Dim number As Integer
        rndnumber = New Random
        number = rndnumber.Next(1, 1001)
        TextBox1.Text = number.ToString
4)That was easy, wasn't it?
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

think ive seen this before but good snip
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Yes i have seen this before, But nice snip anyway.
Image
User avatar
un kn0 wn
VIP - Donator
VIP - Donator
Posts: 269
Joined: Mon Mar 29, 2010 6:12 pm

zachman61 wrote:
think ive seen this before but good snip
Lewis-Froom wrote:
Yes i have seen this before, But nice snip anyway.
Yeas u 2 have probably seen that before than what most "Supposedly keygens" use in vb to randomly select one of the keys feed into the program. Nice Snip Though.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

If you want to make a variable length random number you can use this:
Code: Select all
        Dim times As Integer = 30
        Dim r As Random = New Random()
        Dim out As String = ""

        For i As Integer = 0 To times - 1
            Dim res As Integer = r.Next(0, 10)
            out += res.ToString()
        Next
        TextBox1.Text = out
5 posts Page 1 of 1
Return to “Quick Snips”