srand() and rand()

This is a discussion on srand() and rand() within the C++ Programming forums, part of the General Programming Boards category; So I am trying to get the psuedo random number generator to work. Everywhere I look online tells me this: ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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

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