How do i make a random interger and set the min, max?
Code:#include <stdio.h> /* Random int here */ int randomint = 0; int main() { printf("%d",randomint); return 0; }
How do i make a random interger and set the min, max?
Code:#include <stdio.h> /* Random int here */ int randomint = 0; int main() { printf("%d",randomint); return 0; }
--Seph
FAQ > How do I... (Level 1) > Generate random numbers?
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.*
well the min and max is 0 to RAND_MAX, I think that is defined in stdlib.h, I guess you could undef it to change max but most of us just use modulo operator to correct the result.
look at rand() and srand().
// Dave_Sinkula, you beat me
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
> I guess you could undef it to change max
You can't undef RAND_MAX to change it's value
Use the modulo operator
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.