Thread: srand() Clarification

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    srand() Clarification

    I'm having some problems with random numbers, so I just wanted to double-check this:

    My main() function contains an object MyClassObject.

    MyClassObject contains a member variable MySecondClassObject;

    If I call srand(time(NULL)) in my main() function, then calling rand() from either of my classes should produce a newly randomized list each time I call the program, correct? (I don't have to call srand() in the constructor of each of my classes or anything?)
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  2. #2
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Correct. Unless the constructors are executed out of order (which they shouldn't be), you should be fine.

    To the best of my knowledge

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Mmkay, that's what I was assuming. Looks like it's back to the drawing board then. I've been trying to figure this problem out for the last couple of hours (srand() not actually randomizing, you know, the classic "I can't generate random numbers" problem, but somehow, this one's special and unlike any other), and if I still can't in the next few days, expect to see me back here

    Thanks
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

Popular pages Recent additions subscribe to a feed