Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Random number but in increments of X

Random number but in increments of X

Scheduled Pinned Locked Moved Visual Basic
tutorialquestionlounge
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gerryR com
    wrote on last edited by
    #1

    Hi all I'm working on something where a random num is generated between 0 and a user defined number. I need the random numbers to be in increments of 15 instead of 1 e.g. random numbers between 0 and 90 would only be 0 15 30 45 60 75 90 I figure I can do this by generating the random numbers between 1 and 7 for the above example and then substitute: 15 for 1 30 for 2 etc. etc. But just though I'd ask here in case there's an easier way? Appreciate a point in the right direction, rgds gerryR Below is my rand function

    Private Function genRand(ByVal intX As Integer) 'Function used to generate a random number between 0 and a given number
    Dim intRandNo As Integer
    intRandNo = Int(Rnd() * intX)
    Return intRandNo
    End Function

    L 1 Reply Last reply
    0
    • G gerryR com

      Hi all I'm working on something where a random num is generated between 0 and a user defined number. I need the random numbers to be in increments of 15 instead of 1 e.g. random numbers between 0 and 90 would only be 0 15 30 45 60 75 90 I figure I can do this by generating the random numbers between 1 and 7 for the above example and then substitute: 15 for 1 30 for 2 etc. etc. But just though I'd ask here in case there's an easier way? Appreciate a point in the right direction, rgds gerryR Below is my rand function

      Private Function genRand(ByVal intX As Integer) 'Function used to generate a random number between 0 and a given number
      Dim intRandNo As Integer
      intRandNo = Int(Rnd() * intX)
      Return intRandNo
      End Function

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, just generate a random integer within the appropriate bounds, then multiply by the increment you want. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Fixturized forever. :confused:


      G 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, just generate a random integer within the appropriate bounds, then multiply by the increment you want. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


        G Offline
        G Offline
        gerryR com
        wrote on last edited by
        #3

        Doh! Spot on, thanks :)

        L 1 Reply Last reply
        0
        • G gerryR com

          Doh! Spot on, thanks :)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          you're welcome. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Fixturized forever. :confused:


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups