i do not understand rand() >.<
ok here is my code
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout<<rand()%6;
cin.get();
}
|
i want it to print a random number from 0 to 6
but everytime i test it it always comes out as a 5 >.>?
any help would be nice!
ok my new code is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void timee(){
srand((unsigned)time(NULL));
cout << rand()%6;
cin.get();
cool();
};
int main(){
timee();
}
|
but can i make time anything else besides NULL cause if i hold down
enter i get alot of the same numbers in a row before it changes >.>?
Well, obviously. You're supposed to call srand only once at the beginning of the program.
ahh i see!
ok 1 more question then how do i get a random number for say between 10 and 20?
By adding some constant value to the generated number.
It's a good idea to make a function for that.
Topic archived. No new replies allowed.