Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
All members of a list of random numbers (varying from 0 to 10) should be within a range from 4 to 6.
So the smallest number should be larger than 4, the largest number smaller than 6.
What's wrong with the code above?
(vl-load-com) (defun c:randlist_range_while (/ NoL bot_rg top_rg rd_nr rdnr_lst a b time_start time_end time_el) (setq time_start (getvar "MILLISECS")); set start time (defun LM:rand ( / a c m ) (setq m 4294967296.0 a 1664525.0 c 1013904223.0 $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m) ) (/ $xn m) ) (setq bot_rg 4); bottom range (setq top_rg 6); top range (setq rdnr_lst '(0 10)); start list for random numbers (setq a (car rdnr_lst)) (setq b (last rdnr_lst)) (setq n 5); number of list elements (while (or (< a bot_rg) (> b top_rg)) (setq NoL (+ NoL 1)); loop counter (repeat n (setq rd_nr (* (LM:rand) 10)); random number (setq rdnr_lst (cons rd_nr rdnr_lst)); add random number to list ) (setq rdnr_lst (vl-sort rdnr_lst '<)) (setq a (car rdnr_lst)) (setq b (last rdnr_lst)) ); end while (setq time_end (getvar "MILLISECS")); set end time (setq time_el (- time_end time_start)); time elapsed (princ (strcat "\nNumber of Loop Executions: " (rtos NoL 2 0))) (princ (strcat "\nTime Elapsed in Millisecs: " (rtos time_el 2 0))) (setq temp (vl-princ-to-string rdnr_lst)) (princ (strcat "\nEntire List: " temp)) (princ (strcat "\nSmallest in List: " (rtos a 2 2))) (princ (strcat "\nLargest in List: " (rtos b 2 2))) (princ) ); end defun
Solved! Go to Solution.