It was recommended that I try this:But that keeps giving me zero every time? Am I missing something?Code:double price = 30000 *rand() % 1;
Thanks
It was recommended that I try this:But that keeps giving me zero every time? Am I missing something?Code:double price = 30000 *rand() % 1;
Thanks
Yes, the recommendation is wrong. You could read Prelude's article on using rand() as a starting point.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
what does n % 1 produce?
try a simple program that prints the results
2 % 1
3 % 1
4 % 1
5 % 1
etc
Are you trying to generate a random number that's EITHER 0 or 1, or are you trying to generate some sort of floating point value between 0 and 1?
If the latter, then % and rand() are both integer-only operations and you need to find another way to do this. For example, if you wanted 2 places of precision:
Code:float num = (float)((uint32_t)rand() % 100) / 100;