+ 2
Srand
#include <iostream> #include <cstdlib> using namespace std; int main () { srand(98); { cout << 1 + (rand() % 6) << endl; } } why here it's outputting only 5 everytime?
7 odpowiedzi
+ 4
Add #include <ctime> to header rows
Modify seeder as srand ( time (0) )
+ 1
Ohk
+ 1
then what's the use of using this code which i have mentioned in the question... because it outputs the same number always
+ 1
With regards to your other question on how to get a random number between 1 - 100, this code is almost there. Just replace % 6 with % 101
0
include the correct header file <time>. Then use srand(time()).
But it will only output 1 - 5 because of the %6
0
I suspect it has something to do with your seed. You only allow 1 - 5, but "start" with 98