2 odpowiedzi
0
Maybe you wish to write a simulator to determine probability by using the Monte Carlo technique - that is, trying many random solutions and aggregating the results.
Loop a number of trials as follows:
1. Get a random number within a certain range, say 0 to 100. That will represent where the first break is made of a 100-unit-long stick. Now you have two pieces of known length. If both pieces are the same length (50), or if a piece is either 0 or 100, then mark this trial as a failure and exit to start the next one.
2. Randomly select one piece or the other by using a random integer selection, say betwixt 0 or 1.
3. If the selected piece is the shorter piece then mark this trial as a failure and exit this trial to start the next one.
4. Get another random number from 0 to the selected piece length to divide where the selected piece gets broken.
5. If all pieces are less than half the original length then mark this trial as a success, else mark it as a failure.
6. Exit to start the next trial.