- return real number that >=0 and < 1
RANDBETWEEN(bottom,top)
- return integer in specified range
Note: every Excel calculations, random number will change, to fix the value generated
-> enter =rand() in formula bar and press F9
For example
- =rand() => ex. 0.135
- =rand()*10 => return real number that >=0 and < 10
- =int(rand()*10) => return integer that >=0 and < 10
- =randbetween(1,10) => return integer that >=1 and <=10 (ex. 7)
Random in VBA
RND()
- return single value that >=0 and < 1
Int(Rnd * (bottom- top+ 1)+ bottom)
- return integer in specific range
For example
--------------
Sub test()
Randomize
MsgBox Rnd()
End Sub
=> return single number ex. 0.741725
--------------
Sub test2()
'to find random integer in range between 1 and 10
Dim RandNo As Integer
Randomize
RandNo = Int(Rnd() * 10 + 1) '10 = 10-1+1
MsgBox RandNo
End Sub
=> return integer that >=1 and <=10 ex. 6
--------------
Note: single value is ranging in value from -3.402823E38 to -1.401298E-45 for negative values and from 1.401298E-45 to 3.402823E38 for positive values
No comments:
Post a Comment