Barry Margolin wrote:
> In article <························@cv.net>,
> Ken Tilton <···········@optonline.net> wrote:
>
> > (let* ((nums (list 0 1 2 3 4 5 6 7))
> > (used (make-array (length nums)
> > :element-type 'bit
> > :initial-element 0)))
> > (labels ((show-one (depth)
> > (when (find 0 used)
> > (let ((one (loop thereis
> > (loop for n in nums
> > unless (= 1(bit used n))
> > when (zerop (random (length nums)))
> > return n))))
> > (print one)
> > (setf (bit used one) 1)
> > (show-one (1+ depth))))))
> > (show-one 0)))
> >
> > This is somewhat distorted, but the labeled fn show-one is what I really
> > have to do: given a mask and a list of numbers some of whom have already
> > been "used" indicated by (= 1 (bit mask <that number>)), pick a number
> > at random from those still unused. Without consing.
> >
> > In case it is confusing above, in reality there will be just a dozen
> > random numbers under about 5000, and the mask will be a 5000 bit mask.
> >
> > All I have so far is trying numbers at random in a tight loop.
>
> Count the number of unused elements, pick a random integer N between 1
> and that count, then find the Nth unused element.
Arc
(= nums '(9 22 37 54 61 78 83 92))
(= used '(22 54 83))
(= which (rand (count [~some _ used] nums)))
(let count 0
(each n nums
(if (~some n used)
(do (if (is count which) (prn n))
(++ count)))))