0
Can I store a srand(time(0)) 1 + (rand() % 3) value to a variable?
The title.
5 Antworten
0
Why don't you test it out?
0
I did it,I tried many ways, but the was an eror bcs srand() is void type or rand() was the same everytime, and i mean somehow to store in a variable the result of the rand()
0
Error*
0
#include <iostream>
#include <stdlib.h>
#include <time.h>
using std::cout;
using std::endl;
int main() {
srand(time(0));
int num = rand();
cout << rand() << endl;
return 0;
}
^ That works
0
Yes you can store a random expression; in this case 1 + rand()% 3, in a variable... I did exactly that in the following code.
https://code.sololearn.com/cV4VWzSHaU1Q/?ref=app
Random expression: 1 + rand()% 3;
Variable: int Winner;