Home All Groups Group Topic Archive Search About
Author
6 Aug 2006 2:20 AM
Geoldr
How do I make a random number from 1 to 10?

Author
6 Aug 2006 2:55 AM
iwdu15
take a.look at Random....ex

Private Sub Button1_Click(...)

Dim rnd As New Random

Me.Label1.Text = rnd.Next(1, 11)

End Sub


i believe the .Next method's parameters are

first number = base, bottom number (inclusive)
second number = highest number (non inclusive)

this will give you a "random" number between 1 and 11


hope this helps
--
-iwdu15
Author
6 Aug 2006 4:44 AM
Geoldr
iwdu15 wrote:
Show quoteHide quote
> take a.look at Random....ex
>
> Private Sub Button1_Click(...)
>
> Dim rnd As New Random
>
> Me.Label1.Text = rnd.Next(1, 11)
>
> End Sub
>
>
> i believe the .Next method's parameters are
>
> first number = base, bottom number (inclusive)
> second number = highest number (non inclusive)
>
> this will give you a "random" number between 1 and 11
>
>
> hope this helps
> --
> -iwdu15

Yep, it worked.
Thanks for the help!
Author
6 Aug 2006 10:54 AM
Herfried K. Wagner [MVP]
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb:
> Private Sub Button1_Click(...)
>
> Dim rnd As New Random
>
> Me.Label1.Text = rnd.Next(1, 11)

Note that you should create only a single instance of 'Random' in this case:

\\\
Private m_Random As New Random()
....
Me.Label1.Text = CStr(m_Random.Next(...))
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>