Hurr, getting into the basics of C++ here, and running into issues with calling user defined functions more often that I feel I should. I wrote a mock program to test the issue, and I'm still running into trouble:
It compiles, but it tells me "[Warning] the address of `int randGen()', will always evaluate as `true' " and the only thing it outputs is "1" when I want it to output a random number between 1 and 10.
When I did that it works, but if I try output the value multiple times in a loop, I'd get the same randomly generated number for each time it was called.
>>16
Yeah, that's expected behaviour. Random numbers will do that some times. Because they're random.
Name:
Anonymous2010-11-06 21:39
>>18
an array of 30 random numbers shouldn't all be the same number. and a rerun of the program will result in a different number than the initial run but all 30 outputs will be the same number.
that's not random, there's some flaw in the way the program is grabbing the numbers.
>>19
Well, see, that's just the thing. By the Law of Truly Large Numbers, if enough people run that program, sooner or later any improbable sequence would have happened. It just so happens you were the lucky one.
Name:
Anonymous2010-11-07 0:26
>>16
Maybe because you're seeding using time and your processor is too fast. Try hitting your turbo button before executing your code.
Name:
Anonymous2010-11-07 1:25
Oh, I see! So rand() can only make new numbers so fast.
I added system("sleep 1") to randGen, and it works fine now
thanks, everyone!
I'm actually feeling helpful today. Take out system("sleep 1")and never use that again. Ever. Then move srand ( time(NULL) ); from randGen to the beginning of main.