Hi everyone.

Can anyone please guide me on how can I generate a random number from a group of prset numbers.


For example:-

There is a group of preset numbers:-
1,5,18,100,127,500,626,929.

I want to generate a random number from this group....is there anyway in which we could do this?

Do you mean how can you pick up a random number from given sequence of numbers?
follow this thread :http://www.daniweb.com/forums/thread198944.html

Lemme try and explain it in more details.
I provide the program with the following group of numbers:-

1,5,18,100,127,500,626,929.

Now, all I want is that the output should be a random number from one of these numbers:-

1,5,18,100,127,500,626,929.

This is quite simple actually,

Put all of the Numbers into a array,

Then Generate a random number between 0 and {The Number of Numbers in your array } Including 0 too, So then you can use array [randomnumberindex] to get a random number out,

This is quite simple actually,

Put all of the Numbers into a array,

Then Generate a random number between 0 and {The Number of Numbers in your array } Including 0 too, So then you can use array [randomnumberindex] to get a random number out,

Oh...lol...okay...yeah..that was simple. :D

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.