| 119208 | // swap points between "adjacent" stacks |
| 119209 | // Wilkinson defines adjacent as within step/4 units |
| 119210 | function smoothing(v, thresh) { |
| 119211 | const n = v.length; |
| 119212 | let a = 0, b = 1, c, d; // get left stack |
| 119213 | while(v[a] === v[b])++b; |
| 119214 | while(b < n){ |
| 119215 | // get right stack |
| 119216 | c = b + 1; |
| 119217 | while(v[b] === v[c])++c; // are stacks adjacent? |
| 119218 | // if so, compare sizes and swap as needed |
| 119219 | if (v[b] - v[b - 1] < thresh) { |
| 119220 | d = b + (a + c - b - b >> 1); |
| 119221 | while(d < b)v[d++] = v[b]; |
| 119222 | while(d > b)v[d--] = v[a]; |
| 119223 | } // update left stack indices |
| 119224 | a = b; |
| 119225 | b = c; |
| 119226 | } |
| 119227 | return v; |
| 119228 | } |
| 119229 | function lcg(seed) { |
| 119230 | // Random numbers using a Linear Congruential Generator with seed value |
| 119231 | // Uses glibc values from https://en.wikipedia.org/wiki/Linear_congruential_generator |