From: Brian Candler Date: 2010-08-17T22:36:14+09:00 Subject: Re: can i do this in ruby? a simulation process Bruce Wayner wrote: > 20% of vehicles (1passenger) -> must transfer 100(20% of 500) people > from A -> B No, and in any case that's the wrong approach for a simulation. In any particular run, it's possible (although rather unlikely) that all the vehicles will depart will all be buses. Or that they will all be cars with one driver. In practice, the mix will vary between runs, and you don't know in advance what it will be. Treat each vehicle individually. Each one has its own departure time, its own arrival time, and its own number of occupants. If you do the simulation by hand, you'll see what I mean. To start with, you could use ruby as the random number generator, while you do the rest of the work by hand. Suppose the first vehicle leaves on the dot of 12:00:00 (or 0 seconds past midday). How many passengers does it contain? When does it arrive? When does the second vehicle leave? And so on. -- Posted via http://www.ruby-forum.com/.