Thread: Random function

  1. #1
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127

    Random function

    I made this function just to make the use of random numbers easier in my programs. For some reason the compiler doesn't like it. The error is "void value not ignored as it ought to be".
    Code:
    int random(int range){
        int r;
        r=srand((unsigned)time(NULL))%range;
        return r;
    }
    I have a feeling it is something stupid but I did check this time to make sure that I had the right return thing declared in the beginning. what's wrong???
    ~Sven

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    srand returns void, and is ONLY used for seeding the random number generator. use rand to get a random number, and only call srand once durring the execution of your program.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  3. #3
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Oops forgot about that. Thanks!
    ~Sven

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM