0
Random in c++
hello im trying to generate a random number from 0-3 but i cant seem to get it to work, i already tried rand() but i need to generate it like 50 so that isnt gonna work, does someone know a good solution?
10 ответов
+ 1
Cat Sauce
It doesn't generate 1 number, you just have to add endl
cout << rand() % 4 << endl;
If you get the same output on each run, add
srand(time(0));
before the loop. Don't forget to include ctime header
0
So you want to generate 50 random numbers with the range from 0 - 3? You can use for loop with rand function inside it
0
Agent_I i made a for loop but it only give me 1 number so
3333333.........
0
Cat Sauce
Can you show me how you do it?
0
Agent_I
for(int i = 0; i < 50;i++){
cout << rand() % 4;
}
0
~ swim ~ i didnt understand it
0
~ swim ~ i cant seem to get it to work
https://code.sololearn.com/cwRvGF54GiGt/?ref=app