Hi guys, I am having problems generating a sequence of random numbers determined by the argv argument
when i write ./random 20
I want it to generate 20 random numbers. The problem is it will only show 2, but the interval from 0-9 works well, will show 4, 5, 6 ,7...random numbers.
Here is my code:
test is a class.
test.GenerarPermutacion(argv[1][0]-'0');
1 2 3 4 5 6 7 8
void permutacion::GenerarPermutacion (char argv) {
int j=0;
srand((unsigned)time(0));
for (int i=0; i<argv; i++){
j=(rand()%512)+1;
cout << j << endl;
}
I am sure it the problem must be the argv being a char, but I don't quite understand what is causing the problem, since I understand that -'0' makes the char value be int likewise.