Custom Distribution
It respawns when it hits an edge. Exercise 0.6. I'm not sure if I did this correctly.
Notes
Custom Distribution, Exercise 0.6
He briefly mentions Lévy flights.
const r = p.random();
if (r < 0.01) {
// 1% of the time take a large step
} else {
// small step
}
Accept-Reject Algorithm
Numbers that have an easier time qualifying will be picked more often, and numbers that rarely qualify will be picked infrequently.
while (true) {
// the number that you're checking
const r1 = p.random(1);
// assign a probability
const probability = r1;
// a qualifying random value that decides whether to keep the number
const r2 = p.random(1);
if (r2 < probability) {
return r1;
}
}
Exercise from the book:
Can you map the probability to a quadratic function by making the likelihood that a value is picked equal to the value squared?
He gives and example of a uniform distribution of random step sizes and says to change it:
const step = 10;
const stepx = random(-step, step);
const stepy = random(-step, step);
this.x += stepx;
this.y += stepy;