How do I populate a vector with a random number function?

Can someone please tell me if I can populate a vector with 5 random numbers using a function?
Thank you very much for your help!
Yes, you can. Just make a function that uses the push_back() to put the random numbers into the end of the vector.
closed account (z05DSL3A)
use a for loop to loop 5 times.
use rand to generate a random number see:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html
add the random number to the vector
Thank you both for the help.
I was trying to use my vector in the main() instead of in the function.
But I changed a couple of things and it works now.
Thank you again!
Topic archived. No new replies allowed.