Results 1 to 2 of 2

Thread: Random Int with intervals

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    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.

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    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
  •  



Click Here to Expand Forum to Full Width