7

I was wondering what the way is to get a random number with a range of 1-6, using the rand() method. This is to simulate a dice roll needed for me to find the average of 3 dice rolls so the type will be double.

TLM
  • 245
  • 2
  • 7
  • 13
  • Possible duplicate of [How to generate a random number in C++?](https://stackoverflow.com/questions/13445688/how-to-generate-a-random-number-in-c) –  Apr 21 '19 at 17:55
  • I think this question should be closed, read this: https://stackoverflow.com/a/13445752/5550963 –  Apr 21 '19 at 17:55

1 Answers1

12

This is a simple example to generate randoms between 1 to 6, I think you can figure the rest

#include <iostream>
#include <cstdlib>
#include <ctime>

int main() {
    srand(time(0));
    std::cout << (rand() % 6 + 1) <<std::endl;
    return 0;
}
Nylon Smile
  • 8,990
  • 1
  • 25
  • 34