I can't really fully understand randomizing in C++, can anyone please just put in the code to randomise getting an int number between 1 and 6, plz, i know how to do it with doubles and similar stuff, but i just can't get this
#include <cstdlib> #include <ctime> #include <iostream> using namespace std; int RandInt(int a,int b) { return a + rand() % (b - a + 1); } int x = RandInt(1,6); Code (markup):
I haven't done C for a while, but I think you'll also have to seed the random number generator otherwise the random numbers will be the same for each run of the program. srand is the function, check out http://www.fredosaurus.com/notes-cpp/misc/random.html .