Percolation/Bond percolation: Difference between revisions
Content added Content deleted
(Updated D entry) |
(Updated D entry) |
||
Line 190: | Line 190: | ||
void initialize(in double prob, ref Xorshift rng) { |
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. |
cells[0 .. nc] = bottomWall | rightWall; // First row. |
||
Line 203: | Line 195: | ||
foreach (immutable r; 1 .. nr + 1) { |
foreach (immutable r; 1 .. nr + 1) { |
||
foreach (immutable c; 1 .. nc) |
foreach (immutable c; 1 .. nc) |
||
cells[pos++] = ( |
cells[pos++] = (uniform01 < prob ?bottomWall : empty) | |
||
( |
(uniform01 < prob ? rightWall : empty); |
||
cells[pos++] = rightWall | |
cells[pos++] = rightWall | |
||
(uniform01 < prob ? bottomWall : empty); |
|||
} |
} |
||