# Thread: Help generating multiple random numbers

1. ## Help generating multiple random numbers

Right here is my working code generating a random number and then converting it into binary. Im having trouble trying to generate 3 random numbers. Any help would be appreciated.

Code:
```#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <cstring.h>
#include <ctype.h>
#include <math.h>

#define Population 10
#define Chrom_Length 4

void main(){

int Numbers [Population];
int Binary [Population][Chrom_Length];
int Random;
int Decimal;
int MAX = pow(2,Chrom_Length)-1;
int MostSigBit = pow(2,(Chrom_Length-1));
int CurrSigBit;

srand ( time(NULL));     // Seeds the random number generator
for(int i=0; i<Population; i++)
{
Random = (rand()%MAX); 	// Generate the random number
Numbers[i] = Random; 	// Store the number
}
for(int i=0; i<Population; i++)  // Population for the loop
{
cout<< Numbers[i]<<endl;
}
for(int i=0; i<Population; i++)
{

Decimal = Numbers[i];

for (int j=0; j<Chrom_Length; j++)
{ CurrSigBit = pow(2,(Chrom_Length-j-1));
if (CurrSigBit <= Decimal)
{
Binary[i][j]=1;
Decimal = Decimal - CurrSigBit;
}
else
{
Binary[i][j]=0;
}
}

}

for (int i=0; i<Population; i++)
{
for (int j=0; j<Chrom_Length; j++)
{
cout<<Binary[i][j];
}
cout<<endl;
}
}```

2. Im having trouble trying to generate 3 random numbers.
what are you having trouble with EXACTLY? its easier if you tell us what we're to be looking for.

3. Well where it generates 1 number and the binary equivilent, i now need to make it generate 3 numbers and convert to the binary equivilent. I dont know where to start so any guidence will be appreciated

4. how did you get the first random number? how do you expect to get the next one?

edit: also, for C++ you should use int main not void main, and remove the '.'h from all the #includes, those are for C. however, for 'time.h' it would have to be 'ctime', for example, same goes with 'math.h'. additionally, you have included headers you dont use. use trial and error, commenting one out and trying to compile to see what ones you dont use.