Advertisement
brilliant_moves

lotto.lisp

Aug 1st, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.70 KB | None | 0 0
  1. ; lotto.lisp is a (Common) Lisp program by Chris Clarke 01.08.2018
  2. ; purpose: choose 6 unique random balls in range 1..59
  3.  
  4. (setq highest 59) ; 59 for national lottery
  5. (setq nballs 6)   ;  6 for national lottery
  6.  
  7. (setf *random-state* (make-random-state t))
  8. ; # this initializes the global random state
  9.  
  10. (setf my-array (make-array highest))
  11. (setf chosen-array (make-array nballs))
  12.  
  13. (dotimes (x highest)
  14.    (setf (aref my-array x) (+ 1 x))
  15.    ; my-array holds numbers 1 to 59
  16. )
  17. (dotimes (n nballs)
  18.    (setq r (random highest))
  19.    (setf (aref chosen-array n) (aref my-array r))
  20.    (setq highest (- highest 1))
  21.    (setf (aref my-array r) (aref my-array highest))
  22. )
  23. (write (sort chosen-array #'<))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement