how to randomize the numbers in my random function(dev C++)

This is a discussion on how to randomize the numbers in my random function(dev C++) within the C++ Programming forums, part of the General Programming Boards category; ok so i searched around for a while and found a simple, working random number generating function. however, i am ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    how to randomize the numbers in my random function(dev C++)

    ok so i searched around for a while and found a simple, working random number generating function. however, i am getting the same number over and over again and it would greatly appreciated if someone could help me get actual random numbers. what am i missing?

    this is the simplified code i have so far to just get a random number from 2 dice:

    .................................................. .........................................
    Code:
    
    #include <cstdlib>
    #include <iostream>
    #include <strings.h>
    #include <hat.h>
    #include <ctime> 
    /*i know some of these includes are not needed for the task at hand i am using them for another aspect of the program*/
    
    using std::cout;
    using std::rand;
    using namespace std;
    int main(int argc, char *argv[])
    {
    
        int firstdie;
        int secdie;
        const int HIGH=6;
        const int LOW=1;
    
        firstdie = rand() % (HIGH - LOW);
        secdie = rand() % (HIGH - LOW);
        
        cout <<firstdie<<endl<<endl<<secdie;
        
        
        system("PAUSE");
        return EXIT_SUCCESS;
       }


    .................................................. .........................................

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,773
    Read up on the use of srand.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random/randomize
    By Lynn in forum C Programming
    Replies: 6
    Last Post: 06-05-2006, 03:25 PM
  2. don't want to randomize two alike numbers
    By randomizer in forum C++ Programming
    Replies: 8
    Last Post: 05-26-2005, 07:42 PM
  3. need suggestion for custom randomize function
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2002, 03:59 AM
  4. Problem with Visual C++ ( randomize function )!
    By marCplusplus in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 12:01 PM
  5. Randomize Number Function
    By beyonddc in forum C Programming
    Replies: 3
    Last Post: 12-10-2001, 03:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21