simple question!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • steele20
    New Member
    • Sep 2006
    • 6

    simple question!!!

    I want to make it so I can keep calling randomnumber() and generate numbers between 0 and 2, but I can only make it so it calls it once then prints the same number 3 times. Any clue on how I can fix my code to keep calling randomnumber() ?


    please take a look

    class vacuumcleaner
    {
    public:

    vacuumcleaner() ;
    void randomnumber(in t *number);
    private:

    };


    void vacuumcleaner:: randomnumber(in t *number)
    {
    srand((unsigned )time(0));

    *number = rand()%3;
    }


    vacuumcleaner:: vacuumcleaner()
    {

    for (int u = 1; u < 4; u++)
    {
    cout<<randomnum ber(int &number)<<en dl;
    }
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You should only call srand once when your program starts, not everytime before you call rand

    Comment

    Working...