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.

Re: generate random number 80 80

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)];
Re: generate random number 80 80

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

Be a part of the DaniWeb community

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