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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Random Numbers

Random Numbers

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionlounge
4 Posts 3 Posters 5 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.
  • J Offline
    J Offline
    Josus
    wrote on last edited by
    #1

    hello. Do you have an funcion that gives back "randomized" numbers. for example: ranomize(6) should return 0, 1, 2, 3, 4 or 5. know what I mean? I hope you can help me. I need this funktion for a simulation. The objects should decide by themselves in which direction they will go. :o) life is fun! Johannes //still a newbie

    T D 2 Replies Last reply
    0
    • J Josus

      hello. Do you have an funcion that gives back "randomized" numbers. for example: ranomize(6) should return 0, 1, 2, 3, 4 or 5. know what I mean? I hope you can help me. I need this funktion for a simulation. The objects should decide by themselves in which direction they will go. :o) life is fun! Johannes //still a newbie

      T Offline
      T Offline
      tongc
      wrote on last edited by
      #2

      use the rand function to return a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand.

      1 Reply Last reply
      0
      • J Josus

        hello. Do you have an funcion that gives back "randomized" numbers. for example: ranomize(6) should return 0, 1, 2, 3, 4 or 5. know what I mean? I hope you can help me. I need this funktion for a simulation. The objects should decide by themselves in which direction they will go. :o) life is fun! Johannes //still a newbie

        D Offline
        D Offline
        Daffy d
        wrote on last edited by
        #3

        This works for me : srand( (unsigned)time( NULL ) ); // Initialise rand with the current time to get // a truly random seed int ivariable = rand() % 5 // result between 0 and 5

        J 1 Reply Last reply
        0
        • D Daffy d

          This works for me : srand( (unsigned)time( NULL ) ); // Initialise rand with the current time to get // a truly random seed int ivariable = rand() % 5 // result between 0 and 5

          J Offline
          J Offline
          Josus
          wrote on last edited by
          #4

          thanks Daffy d. wrote: int ivariable = rand() % 5 // result between 0 and that is exactly what I needed. I didn't know how to chance the RAND_MAX value! You helped me a lot! :o) life is fun! Johannes //still a newbie

          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