Percolation/Bond percolation: Difference between revisions

Updated D entry
(Updated D entry)
(Updated D entry)
Line 190:
 
void initialize(in double prob, ref Xorshift rng) {
static assert(rng.front.min == 0);
immutable thresh = cast(uint)(rng.front.max * prob);
bool randP() { // Performance optimization.
immutable result = rng.front < thresh;
rng.popFront;
return result;
}
 
cells[0 .. nc] = bottomWall | rightWall; // First row.
 
Line 203 ⟶ 195:
foreach (immutable r; 1 .. nr + 1) {
foreach (immutable c; 1 .. nc)
cells[pos++] = (randPuniform01 ?< prob ?bottomWall : empty) |
(randPuniform01 < prob ? rightWall : empty);
cells[pos++] = rightWall | (randP ? bottomWall : empty);
(uniform01 < prob ? bottomWall : empty);
}