   generating a random number list
  Hi guys, I am trying to write a program that generates a random number between two number X and Y (excluding X and Y)I have written the formula for doing this but when i implement writing a list of 10 numbers using a for loop:for (i = 0; i < 10; ++i)it just gives a list of 10 of the same number everytime i execute. (they are different every time i execute)I have seeded the random number part by:srand (time(0));I am guessing that all the numbers in the list are created at the time of execution, hense  them all being the same.How do I create a list of 10 different random numbers (same one can occur multiple times if need be)Cheers   
  Show how you're generating the numbers. Also, did you call srand() more than once?   ;  int guess = (x + 1) + (random % (y - 1 - x));this gives a number between x and y not including x and ysrand() called once   ;  And how is random defined? Is it a variable? If so, do you reassign its value every time you calculate guess?   ;  The code is thus so far:#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){int x = 12;int y = 45;int guesses = 0;srand (time(0));int random = rand();int guess = (x + 1) + (random % (y - x - 1));for (guesses = 0; guesses < 10; ++guesses)cout << "You guessed " << guess << endl;system ("PAUSE");return 0;}Thank you for your help   ;  If you want a new random number every time, you'll need to call rand() in your loop.   ;  Oh, here's a really cool funcion that returns a random number.   ;Quote:Original post by redmancThe code is thus so far:#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){int x = 12;int y = 45;int guesses = 0;srand (time(0));int random = rand();int guess = (x + 1) + (random % (y - x - 1));for (guesses = 0; guesses < 10; ++guesses)cout << "You guessed " << guess << endl;system ("PAUSE");return 0;}Thank you for your helpYou'll want to re-assign guess in each iteration of the loop.  Right now you assign it once and loops 10 times saying what it's value is.   ;  argh, I cant get it right. Do you mean put int guess = (x + 1) + (random % (y - x - 1)); inside the loop?what about srand (time(0));int random = rand();where do they go?Tried all combos   ;#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){   int x = 12;   int y = 45;   int guesses = 0;   srand (time(0)); for (guesses = 0; guesses < 10; ++guesses)   { int random = rand(); int guess = (x + 1) + (random % (y - x - 1)); cout << "You guessed " << guess << endl;   }   system ("PAUSE");   return 0;}Maybe this will work...   