- ((copy (copy-list agent-set)))
- (append
- (loop for i to (- (length copy) 2)
- for idx = (+ i (cl-nl.random:next-int (- (length copy) i)))
- for next = (nth idx copy)
- do (setf (nth idx copy) (nth i copy))
- collect next)
- (last copy))))
+ ((copy (copy-list agent-set))
+ (i 0)
+ (agent nil))
+ (flet
+ ((fetch ()
+ (let
+ ((idx (when (< i (1- (length copy))) (+ i (cl-nl.random:next-int (- (length copy) i))))))
+ (when idx (setf agent (nth idx copy)))
+ (when idx (setf (nth idx copy) (nth i copy)))
+ (incf i))))
+ (fetch) ; we pre-fetch because netlogo does, rng sync hype!
+ (lambda ()
+ (cond
+ ((> i (length copy)) nil)
+ ((= i (length copy)) (incf i) (car (last copy)))
+ (t (let ((result agent)) (fetch) result)))))))