Non-repeating random integer number generator in Lisp


(defun random-pick (n)
  (loop 
    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).

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

The URI to TrackBack this entry is: https://burubaxair.wordpress.com/2012/12/30/non-repeating-random-integer-number-generator-in-lisp/trackback/

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: