Thread: random undeclared?

  1. #1
    Registered User ytaipsw's Avatar
    Join Date
    Mar 2006
    Posts
    41

    Question random undeclared?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        long int hat;
        
        hat = random(); /*use rand() for short ints*/
        printf("%d is a random number.\n",hat);
        return(0);
    }
    when i try to compile this it says random undeclared
    thanks
    -ytaipsw

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The function is actually rand(), and you need to seed it first with srand(). There are details on the crpogramming.com site, or you can search the web.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    The function random is nonstandard, so it appears you are using code with a compiler that does not have support for that code. Use the standard rand, or tell us more specific details about your needs.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User ytaipsw's Avatar
    Join Date
    Mar 2006
    Posts
    41
    thats all i needed to know, thanks guys

    -ytaipsw

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM