954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Generate a random number from a preset group of numbers

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?

Nikhar
Junior Poster in Training
76 posts since Feb 2009
Reputation Points: 29
Solved Threads: 0
 

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

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 
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.

Nikhar
Junior Poster in Training
76 posts since Feb 2009
Reputation Points: 29
Solved Threads: 0
 

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,

Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
 

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

Nikhar
Junior Poster in Training
76 posts since Feb 2009
Reputation Points: 29
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You