Hi Everyone!

Is there anyway to create A program which can demonstrate the following function:
A capsule machine(Similar to a candy machine),when you,say,insert a coin into it and can randomly pop out a capsule containing an item in it?

How(or any possible way)is to code the probability for a particular capsule which contains the rare items in it to pop out?(example: If the machine has total of 10 capsules in it.1 contains a red ball,3 with blue balls and 6 black balls.So the probability for the only red ball to come out would be 1/10)

Right now I only have the idea but not skilled enough to create.

Anyone can point me in the direction of achieving this problem?

Cheers!

Anything is possible, but Can you be more specific?

Do you want to run through the whole candy machine and display what was popped or only the first pop?

I just want to display only the first that pops out.

Specifically Its just a capsule machine where you can press a button and display out the result in messagebox of what the first item it pops out.But I don't know how to set the probability for my items.

Well, if it is logic you want.

You could simply set a string array

say
capsule[0]= "Red";
capsule[1-3]= "Blue";
capsule[4-9]= "Black";

and the just do x = Random 1 to 10

print capsule[x]

Thank You Finito.
I'll try and work it out.

Be a part of the DaniWeb community

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