# randon numbers

• 10-19-2002
mcorn
randon numbers
Hi,
Could someone look at this and tell me where my mistake is? Thanks. Mcorn
Code:

```#include <iostream.h> #include <stdlib.h> int Fill_It(int, int, int, int [20]); int i; int sample[20], sample2[20], number; int t=0; int main(void) {   cout << "Please enter a seed number: " ;   cin >> t;   Fill_It(t, 1000, 2000, sample);   cout << "Twenty random numbers from 1000 to 2000\n\n";   cout << "Seed: " << t << endl;           for(i = 0; i < 20; i++)                 cout << sample[i] << endl;   cout << "Please enter another seed number: " ;   cin >> t;   Fill_It(t, 0, 1000, sample2);         cout << "Twenty random numbers from 0 to 1000\n\n";         cout << "Seed: " << t << endl;           for(i = 0; i < 20; i++)                 cout << sample2[i] << endl;   return 0;   } Fill_It(int seed, int low, int high, int test[20]){         srand(seed);         i = 0;         while(i <= 20){                         number = rand() % high;                         if((number >= low) && (number <= high)){                                         test[i] = number;                                           i++;                                           }                         else                                 ;           }         return 0; }```
• 10-19-2002
Hammer
>>Could someone look at this and tell me where my mistake is?
What is this, a "Spot The Bug" competition ?! :confused: :D

Tell us what you think is wrong to save us reading and debugging each line of your code....
• 10-19-2002
mcorn
Hi,
I'm sorry, I was tactless on my question! What I'm trying to do is generate random numbers between 1000 and 2000. Next, I'm generating random numbers between 0 and 1000. I can't get it to compile and I've been looking at it for the past hour or so. I thought if another person that is not aggrevated and with a fresh set of eyes might see something right away. I'm sure it is something very minor. ( at least I hope) thanks. Mcorn
• 10-19-2002
Hammer
>>while(i <= 20){
This will overflow the buffer. You need
>>while(i < 20){