C++ Randomizing

Discussion in 'Programming' started by The Bard, Nov 5, 2006.

  1. #1
    I can't really fully understand randomizing in C++, can anyone please just put in the code to randomise getting an int number between 1 and 6, plz, i know how to do it with doubles and similar stuff, but i just can't get this
     
    The Bard, Nov 5, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    
    using namespace std;
    
    int RandInt(int a,int b)
    {
         return a + rand() % (b - a + 1);
    }
    
    int x = RandInt(1,6);
    
    
    Code (markup):
     
    nico_swd, Nov 5, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    TwistMyArm, Nov 5, 2006 IP
  4. The Bard

    The Bard Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thx Guys, that really helped. Getting ready for the ACSL, you know...
     
    The Bard, Nov 6, 2006 IP