Reputation: 1551
I am trying to generate random integers over the range (-5, 5) using VBA, something like 100+/- rnd 5. I was wondering if some of you has more elegant way to do it. What I have so far is only "+"
randomRange= 100 + CInt(Rnd * 5)
Upvotes: 1
Views: 7859
Reputation: 27478
You can use Excel's RANDBETWEEN
function like this:
randomRange= 100 + Application.WorksheetFunction.RandBetween(-5, 5)
Upvotes: 3
Reputation: 1551
I have found a solution.
randomRange=100 + cint((Rnd()*((-1)^INT(rnd()*10))) * 5)
Where
Thanks to DRJ on Mr. Excel Forum
Upvotes: 0