Trouble with random number generator.

Ok so I'm working my way through a c++ book and as a project on my own I wanted to write a program to simulate the roll of a die 10 times. The only problem is when I run the program it will only roll the same number 10 times. Example if the program rolls a 5 it will roll 10 5 in a row, and I don't know why.

Here is the code.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main ()
int count = 0;
while (true)
count += 1;

if (count > 10)


int RandomNumber = rand();

int die =(RandomNumber % 6) + 1;
cout << "You rolled a " << die << endl;


int exit; // I added this just as a way of running the program
cin >> exit; // and having it close when I give it the ok
return 0;


Any help will be greatly appreciated.
Last edited on
Only call srand once, before the first call to rand.
Do you mean I need to move it?
Considering that in its current location it will be called more than once, yes.
Ok its working properly now thanks guys.

Topic archived. No new replies allowed.