0

Can I store a srand(time(0)) 1 + (rand() % 3) value to a variable?

The title.

7th Jan 2019, 9:45 AM
Platinoob_
Platinoob_ - avatar
5 Antworten
0
Why don't you test it out?
7th Jan 2019, 11:07 AM
Rain
Rain - avatar
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()
7th Jan 2019, 12:41 PM
Platinoob_
Platinoob_ - avatar
0
Error*
7th Jan 2019, 12:41 PM
Platinoob_
Platinoob_ - avatar
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
7th Jan 2019, 3:50 PM
Rain
Rain - avatar
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;
7th Jan 2019, 8:58 PM
Grandad
Grandad - avatar