Random Value

S

Shapper

Hello,

I declared, in my aspx.vb code, a variable of type integer.

How can I set its value to a random value which can be only 1,2,3 or 4?

Thanks,
Miguel
 
S

Scott M.

Dim X As new Random()
Dim theNum As Short = x.Next(1,5)

Notice the max. value is set to 5, not 4. This is not very well documented,
but you will never get the max. value you specify, only values up to, but
not including the max.
 
S

Shapper

Thank You Both.

Cheers,
Miguel

Dim X As new Random()
Dim theNum As Short = x.Next(1,5)

Notice the max. value is set to 5, not 4. This is not very well documented,
but you will never get the max. value you specify, only values up to, but
not including the max.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top