From: vanekl
Subject: Re: Another From the Trenches Kenny Gotta Be a Better Way Challenge
Date: 
Message-ID: <fsbme9$ohn$1@aioe.org>
Ken Tilton 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.
> 
> kenny

For future googlenauts, this show-one algorithm is not guaranteed
to terminate for all "nums" inputs, especially if you are using a
crappy psuedo-random number generator. Buyer beware.