0

We are tasked to display 100 numbers ranging between 1 -30 using the read_array function, find its mode using a different function and display the result using another one. Then, we have to use the same function to initialize a new integer array with same size (100) to random numbers but this time, the range has to be between 1 and 200. I will then have to use this range to find the 2 smallest number. There's more into the that but my only concern right now is what I am asking for. I'm a little clueless on how to go about it. Here's what I have:

//Function Prototypes
void read_array(int [], int);
void print_array (int [], int);
void sortRand (int[], int);
void Mode (int[], int);
void Two_smallest(int [], int, int*, int*,int*, int*); //Part2


void read_array(int nums[], int SIZE)
            {
                srand(time(0));
                for (int i = 0; i < SIZE; i++)
                {
                    nums[i] = (rand() % 30) + 1;
                }

            }

P.S. I am not getting the same sequence. My code generates different random numbers every time I run the program so that is not the issue.

  • What problems do you have calling the function? That you get the same numbers? That's probably because you call `srand(time(0))` within the same second twice, resetting the seed. Move the `srand` call to the `main` function before you start doing anything else. – Some programmer dude Sep 14 '16 at 18:41
  • Please read http://en.cppreference.com/w/cpp/numeric/random and watch https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful – Jesper Juhl Sep 14 '16 at 18:43
  • Or is the problem that you want to use the same function, but with different *range* for the random number? Then pass the range as an argument? – Some programmer dude Sep 14 '16 at 18:47

0 Answers0