Probability & non-uniform distributions
random()to produce “non-uniform” distributions of random numbers. This will come in handy throughout this course as we look at a number of different scenarios. When we examine genetic algorithms, for example, we’ll need a methodology for performing “selection”—which members of our population should be selected to pass their DNA to the next generation? Remember the concept of survival of the fittest? Let’s say we have a population of monkeys evolving. Not every monkey will have an equal chance of reproducing. To simulate Darwinian evolution, we can’t simply pick two random monkeys to be parents. We need the more “fit” ones to be more likely to be chosen. We need to define the “probability of the fittest.” For example, a particularly fast and strong monkey might have a 90% chance of procreating, while a weaker one has only a 10% chance.
random()function with probability in code. One technique is to fill an array with a selection of numbers—some of which are repeated—then choose random numbers from that array and generate events based on those choices.
- between 0.00 and 0.60 (60%) –> Outcome A
- between 0.60 and 0.70 (10%) –> Outcome B
- between 0.70 and 1.00 (30%) –> Outcome C__
Walkerwith the following probabilities:
- chance of moving up: 20%
- chance of moving down: 20%
- chance of moving left: 20%
- chance of moving right: 40%