Hi,
I have googled but found nothing about this.

I am trying to generate a random number from a given array. But how do i do it?

Suppose:
I have an array int arr[]={3,89,99,4,55};
and i want to generate a random number among these numbers.

thanks in advance.

All you need to do is use rand to get a random number in the range of your array and then use that number for the index of your array. Something like this:

cout << arr[(rand() % sizeOfArray)];

Thanks Nathan Oliver. Really helped!! ...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.