@thi.ng/grid-iterators
Version:
2D grid and shape iterators w/ multiple orderings
15 lines (14 loc) • 422 B
JavaScript
import { shuffle } from "@thi.ng/arrays/shuffle";
import { SYSTEM } from "@thi.ng/random/system";
import { range } from "@thi.ng/transducers/range";
import { __opts } from "./utils.js";
function* random2d(opts) {
const { cols, rows, tx } = __opts(opts);
const rnd = opts.rnd || SYSTEM;
for (let i of shuffle([...range(cols * rows)], void 0, rnd)) {
yield tx(i % cols, i / cols | 0);
}
}
export {
random2d
};