random()?

This is a discussion on random()? within the C++ Programming forums, part of the General Programming Boards category; can anyone explain me the usage of random function
what does this line mean?
radom() %10;...

the %10 means that the output will be between 0 and 10..if it was %20, that would make a random number between 0 and 20...one million is the highest number that you can put behind the % (dont you just hate counting 0's?)...hope that helps

My original post wasn't totally accurate. The highest random value Dev-c++ 4 can produce is 32767, not a million, civix. Still, that's totally compiler dependant. It could be something totally different on Dev-c++ 5...

Your compiler can return 10 when taking mod 10? Would you tell me that for which x does this return 10: x%10 ? I don't think that Dev-C++ developers where so dummy that they created compiler which returns 10 when taking modulus 10. Same like if Microsoft created a compiler which returns 3 when calculating 3-2...

Originally posted by civix SINCE DEV-C++ WAS CREATED, HAMMER!!!
THOSE ARE THE GUIDELINES FOR DEV-C++

- no need to shout, I can hear you loud and clear.
- You stated this

one million is the highest number that you can put behind the %

... and I took that to be regarding the modulos operator (ie nothing to do with random number functions). Even if you were talking about the random() function, you're still wrong, as the number following % has nothing to do with the return from random().

Eg if random() returned 32,000 and the calculation might be
>32,000 % 1,000,001L
which is perfectly valid, as far as I know, although the result will of course be 32000. Maybe you can put me right and prove it isn't valid?!

to get remainders in assembly code you divide a 64-bit number by a 32-bit number and get a 32-bit remainder and a 32-bit devisor. one million isn't even a power of 2. dev-c++ may have that limitation for some reason, but theoretically it should work fine with values in a normal integer's range.