srecord noeq NonOverlappingRandomRects(int n, Rect full, int rw, int rh) { int maxFailures = 1000, failures; new L out; run { double factor = doubleRatio(rw*rh*n, area(full)); if (factor > 1) fail("Can't fit " + n2(n, "rectangle") + " in " + full); loop: while (l(out) < n && failures < maxFailures) { Rect rNew = randomRect(rw, rh, full); for (Rect r : out) if (rectsOverlap(r, rNew)) { ++failures; continue loop; } out.add(rNew); } } L get() { run(); ret out; } }