random number generation

  • Thread starter Thread starter nyn04
  • Start date Start date
N

nyn04

how would I write code to generate a random number only between 1-3
say with whole nubmers such as 1,2,3, 4 etc

thank
 
Dude,

You can do something like:

Sub test()
MsgBox Int((30 - 1 + 1) * Rnd + 1)
End Sub

This will generate random numbers between 1 and 30.

regards,
Robert
 
Also see replys under your separate thread in
microsoft.public.excel.misc. Please do not separately post the same
question to multiple newsgroups.

Jerry
 
nyn04

' Another way a little more random see "Randomize Statement"
' vba or vb help

Private Sub Label1_Click()
Dim n
' Initialize random-number generator.
' Uses the system timer
Randomize
' Generate random value between 1 and in this case 30.
n = Int((30 * Rnd) + 1)
Label1.Caption = n

End Sub


Good Luck
TK



wrote:
 

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

Similar Threads


Back
Top