Stdlib.h

Started by
19 comments, last by Metal Typhoon 22 years, 10 months ago
i got the rand() % 10; but i wanna know what does the srand(time(NULL)) does ?

And one more question if i buy vc++ standard does it come with any book ?

Thanks

"The shortcut is not always the best way "

Metal Typhoon
Metal Typhoon
Advertisement
>> I have a vc++ version that i got on the internet
Warezing a compiler!!

Yea you can go read www.msdn.microsoft.com but it''s
kind of unstructured.

for ansi standard c functions
http://www.tcnj.edu/~cs/doc/CStdLib.html
This is getting a little hard without dodumentation. I''ve mostly used borland , now i''m going to Vc++ so i need a good vc++ begginers book and a c++ book , that is based in standard library.

Does anybody know any of those books there ?

"The shortcut is not always the best way "

Metal Typhoon
Metal Typhoon
quote:Original post by Metal Typhoon
what does the srand(time(NULL)) does ?


It generates a new random number seed based on the current CPU time. This will ensure that numbers generated by rand() are actually somewhat pseudo-random. Just for fuy, try omitting that line, and then running your program a few times .

~~~~~~~~~~
Martee

Edited by - Martee on June 28, 2001 12:31:50 AM
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
srand(time(NULL));

seeds the random number generator with the current time.

Computers can''t generate real random numbers (without getting some random input, like white noise). The rand() function generates a list of numbers based on a fairly complex algorithm, but it is actually ordered and generally it will give you the same sequence of numbers every time you call it (because the next number is based on what the last number is).

So, try writing a program that simple calls rand() 10 times and prints the results, run it a bunch of times. You''ll probably notice it spits out the same 10 numbers every time. Not very random right? srand allows you to ''seed'' the number generator. Using the current time is a fairly fast & somewhat randomish way of getting a unique starting point for the numbers, so that they appear to be more truly random.
Yeah now i got it. Thanks

And a have a question . Is that part of the standard library ? If it''s can u tell me any book just about STL !!? Thanks again guys !!

"The shortcut is not always the best way "

Metal Typhoon
Metal Typhoon
rand() and srand() are parts of the standard C runtime library. Not the STL (which is C++ specific). A good book on C that covers the standard C runtime library is The C Programming Language by Kernighan & Ritchie. Considering they invented C, they know a thing or two about the language. Any bookstore with a good computer section (which is fairly rare, unfortunately) should have this. Or order online through B&N, or FatBrain.

A good book (well, books, really) on C++, including the STL is Bruce Eckel's Thinking in C++. You can even download this (in HTML or PDF format) which is very nice. Look here for more information:

http://www.mindview.net/Books

A lot of people also like the C++/STL books written by Scott Meyers. I don't personally have any experience with them, but considering how popular they are I'm guessing they are pretty good. Again, these books should be in most good bookstores or online bookstores.

Edited by - gmcbay on June 29, 2001 1:06:05 AM
Thank''s man ! i really appreciate your help. I want to buy the STL, cuz i don''t like C as much as c++.

"The shortcut is not always the best way "

Metal Typhoon
Metal Typhoon
Do you know if this is a god bok in STL ? The C++ Standard Library : A Tutorial and Reference ?

Here, see it !

"The shortcut is not always the best way "

Metal Typhoon
Metal Typhoon
STL does a completely different job to the C run time libraries. STL is great for off-the-shelf linked lists, vectors, iterators and other template classes (hence the name standard template library) Im guessing that you havent learnt what templates are yet, (let alone linked lists, vectors and iterators) so forget about them for now, they are confusing and complicated and not something you want to jump into until you have the basics down (like being able to debug your own code for example)

Read your sig - dont try and learn to code the short way - you have to do it the long way. Get a basic beginners C/C++ book. Do the examples.

This topic is closed to new replies.

Advertisement