on-internet
← Community

Trying to return an array containing random numbers in C++ [duplicate]

Stack Overflow ·

I am writing a function that generates a random set of numbers. I can print the numbers as separate ints, but I am trying to put the numbers into an array and return the array so I can assign it to another empty array in another function so I can manipulate the array. I looked everywhere, but I couldn't find something that can satisfy my criteria. My function: void generateRandomNumbers(int lower, int upper){ int n = 5; int random[n]; int tempArr = random[n]; srand((unsigned) time(NULL)); for (int i = 0; i < n; i++){ random[i] = lower + (rand() % upper); cout << random[i] << " "; } } This func

Comments

Sign in or sign up to comment and upvote.

No comments yet.