C ++ random number w / range 1-6

I was wondering how to create a random number with a range of 1-6 using the rand () method. This should mimic the roll of bone needed to find the average of 3 cubes so that the type is double.

+4
source share
2 answers

This is a simple example to generate random numbers between 1 and 6, I think you can portray the rest

#include <iostream> #include <cstdlib> #include <ctime> int main() { srand(time(0)); std::cout << (rand() % 6 + 1) <<std::endl; return 0; } 
+9
source

How to make it stop generating numbers when the number 1 is generated?

0
source

Source: https://habr.com/ru/post/1335203/


All Articles