1234
srand(static_cast<short>(time(0))); short sword1 = rand() % // (1 - 3) + 1;
rand() % (max - min + 1) + min;
123456789101112131415
#include <iostream> #include <ctime> #include <cmath> int main() { int min = 3; int max = 5; std::srand(std::time(0)); for (int i = 0; i < 10; i++) { int r = rand() % (max - min + 1) + min; std::cout << r << std::endl; } }