MECH 215 Lecture Notes - Lecture 5: Local Variable, Global Variable, Function Prototype
Document Summary
There is a c-based library which contains several types, and functions which are used in manipulating program time. This library contains a function called time() which returns a value of type time_t, which is an integral type. If one invokes the function time() with argument of 0, function time() returns the current value of time. If we cast the return type to an unsigned int , then this value can be used as the seed value to function srand(). Thus, new a new pseudorandom sequence of numbers can be generated everytime a program is run, without asking the user for a seed value: // time() to return a value which is used. #include // needed for rand() and srand() Every time we now run the program, a different sequence of numbers is produced: ted@flash programs 9:54pm >random_with_time. In addition to library functions c++ allows the programmer to define their own functions.