(define (make-name-list seed-names)
;; The type the list is built from
(define-type blob-name
name
(random init: 0)) ; Used for sorting
(let ((unused-name-list '()))
(define (randomise-list)
; Assign each name a random number and then sort them
(map (lambda (x) (blob-name-random-set! x (random-integer 65536))) unused-name-list)
(sort! unused-name-list (lambda (x y)
(if (< (blob-name-random x) (blob-name-random y)) #t #f))))
;; Put all the seed names in the list
(map (lambda (x) (push (make-blob-name x) unused-name-list)) seed-names)
(lambda (message . arguments)
(cond ((eq? message ':get-name!)
(if (null? unused-name-list)
"No names available"
(begin
(let ((name (blob-name-name (car unused-name-list))))
(set! unused-name-list (cdr unused-name-list))
name))))
; Add a name to the list, used to return names once they're no longer needed
((eq? message ':put-name!)
(push (make-blob-name (car arguments)) unused-name-list)
(randomise-list))
; Debug, print the internal display
((eq? message ':display)
(display unused-name-list))
(else (error 'name-list "unrecognized message"))))))
;; Test drive code.......