|
-
Sep 19th, 2008, 04:09 PM
#1
Thread Starter
Lively Member
Random Int with intervals
Hi.
I am in need of a function that generates a random number in intervals for example.
RandI(0,100,25)
Get a random number between 0 and 100 with intervals of 25. So it would only return a possible of 4 numbers: 0,25,50,100
RandI(0,100,10) would return either 0,10,20,30,40,50,60,70,80,90 or 100.
While I know how to get a random number, I am unsure of how to do so with an interval. Any help would be great.
Thanks.
-
Sep 19th, 2008, 08:35 PM
#2
Re: Random Int with intervals
Code:
Public Function RandomInterval(plngMin As Long, plngMax As Long, plngInterval As Long) As Long
RandomInterval = Int(((plngMax - plngMin) \ plngInterval + 1) * Rnd) * plngInterval + plngMin
End Function
Don't forget to put Randomize in your program's startup.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|