How can I get a random number that's sometimes negative, and sometimes positive?
Printable View
How can I get a random number that's sometimes negative, and sometimes positive?
VB Code:
Dim intRnd As Long Randomize intRnd = Int((999 - -999 + 1) * Rnd + -999) MsgBox intRnd
I'm not sure chrisjk's code is going to work as is.
Anyway - here's another version
Code:
Function num() as integer
Dim j as single
dim i as integer
j = rnd
if j> .5 then
i = 1
else
i = -1
end if
num = int (rnd*999 +1) * i
End Function
certainly does, tried and tested
Yes it works, perhaps you should have tested it mcnamara