I'm studying for my exams. I was testing a program from my course, but it doesn't seem to work. I was using the functions randomize() and random(100)+1. According to our teacher, these prototypes should be declared in <stdlib.h>. I included this header-file, but the compiler keeps giving an error:missing prototype for randomize, missing prototype for random. Can anyone help me asap please? I've been staring myself blind on this problem.
Wrong language. I remember pascal had the functions randomize() and random().
in C they are called srand() and rand().
Thank you very much for your help, the program does work now. I found in a FAQ that you have to use the time-function. I used it and it worked, but I don't understand what it does. Would you mind explaining that to me?
Would anyone care to explain this to me?
Originally Posted by Lynn
time returns a value that will be different at least every second, which makes it an easy first choice to seed the random number generator.
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.*
rand basically produces only one sequence of numbers. That means it calculates the new result from the result of the previous run. By calling srand you actually just set the starting point in this sequence. By using the current system-time to seed the function you will get a different sequence each time you run your program.
But you should use google to find out more about pseudo random generators. I'm shure there are much better explanations on the net.
Frequently Quite Prolix
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/