(until (is (len winset) set-count)
(let n (rand:1up top)
(if (>= n bottom) (insortnew < n winset))))
is not optimal.
Because, say if `bottom' is 30 and `top' is 40, in nearly the 3/4 of times, you'll call 'rand but not use the result, and you'll make a wasted loop turn.
A solution:
(def genWIN->Nums2 (set-count bottom top)
"Generates a list of `set-count' random numbers, each
in the range between `bottom' and `top' (inclusives).
The generation doesn't waste any CPU cycle :-)."
(let winset nil
(until (is (len winset) set-count)
(let n (rand (- (1up top) bottom))
(insortnew < (+ n bottom) winset)))
(prall:pretty-nums winset)))
The idea is, for `bottom'=30 and `top'=40, to get a random number between 0 and 11, and then add `bottom' to it.
That's awesome. I hadn't gone that far... and have yet to create any sort of habitual thinking around optimizations...
Need to think like you more.
Thanks.
T.