Non-repeating random integer number generator in Lisp

(defun random-pick (n)
    with num 
    until (= (length rand-lst) n)
      when (not (find (setf num (random n)) rand-lst))
        append (list num) into rand-lst 
    finally (return rand-lst)))

It returns a list of n random integer numbers between 0 and n-1. The numbers are different (no repetitions).

Published in: on 30/12/2012 at 22:36  Comments (1)  

The URI to TrackBack this entry is:

RSS feed for comments on this post.

One CommentLeave a comment

  1. Thanks for providing these sort of very good subject matter.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: