+ 2

I'm having trouble generating a random number

I'm making a game in which the user is given a random number between 1 and 4, which depending on the number will roughly output the amount of damage you've done(eg. 1 would be small damage). this number would then be multiplied by 10 and subtracted from the enemy health. the problem is, when I run it, the enemy always takes 10 damage, meaning that i keep getting 1 each time. I have a strong feeling that the "stand((unsigned)time(0)) " function is the problem, but I'm not sure. https://code.sololearn.c

26th Jul 2017, 7:53 PM
X-1
X-1 - avatar
2 Answers
+ 2
`srand(time(nullptr))` gives a new seed for the rand() function.. So that can't be a problem. Also.. Your link is not the link towards your playground.
26th Jul 2017, 8:01 PM
Meine
Meine - avatar
0
avoid rand() for games, c++11 has better utilities for that http://en.cppreference.com/w/cpp/numeric/random look at this https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful for more info
18th Aug 2017, 5:51 PM
Mindaugas Vinkelis
Mindaugas Vinkelis - avatar