randomly selecting already inputed number

hey guys just want to know if i had a stream of numbers(1,1,2,5,8) and want to select at random one of the 5...hw do i go about doing dat using rand() or srand()

http://www.cplusplus.com/reference/cstdlib/rand/

They can give you a number in range from 0 to 4. Where did you store the numbers?
array
#include <ctime>
#include <cstdlib>
#include <iostream>

int main()
{
srand(time(0));

int randomNumber = ((int[]) {2, 5, 22, 55, 332})[rand() % 5];

std::cout << randomNumber << std::endl;

return 0;
}
You kind of double posted.
http://www.cplusplus.com/forum/beginner/125933/


Anyways I think you need to check out how arrays work.
http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.