Thread: srand() and rand()

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    21

    srand() and rand()

    So I am trying to get the psuedo random number generator to work. Everywhere I look online tells me this:

    1) Include the ctime and cstdlib headers.
    Done.

    2) Use something like the system time to seed the generator exactly like this.

    Code:
    srand(time(0));
    Error.

    3) Call rand() to generate random number.

    Unfortunately I only get to step two. I recieve an error during compilation that says that function, srand(), written exactly as seen above, does not evaluate to a function taking one argument. What could be causing this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Having a local variable with the same name as the function usually generates that kind of warning.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    21
    So, this compiles, but I'm not sure if it's working properly...

    Code:
    srand(time);

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    21
    Well I did have a local variable called time, mistake of impatience. Thanks

Popular pages Recent additions subscribe to a feed