Pat wrote:

I am a C++ beginner, please give me some suggestion on the following

question.

Given n balls. The probability pi is the chance to choose ball i. Sum of pi

is 1.

I want to run 10000 independent trials in selecting the ball, and simulate

the expected number of each ball to be choosen.

I have no idea how to implement the probability drawing step. Could you give

me some hints?

This is not really a C++ language question, and as such it doesn't belong

here, in all honesty. Please ask generic programming questions in

comp.programming and generic mathematics questions in sci.math.

Some hints: usually simulating with a computer something that occurs at

random requires the use of pseudo-random number generator. There is one

in the Standard C++ library. Its interface consists of two functions

named 'rand' and 'srand'. Since computers are pretty much deterministic

devices when it comes to programmed behaviour, simulating real-time random

situations with computers is tricky and requires some assumptions to be

made. You need to figure out what "10000 independent trials" really means

because if it's all in the same program, it's not really _independent_.

Victor