Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm having issues with a lisp.
I'm trying to get a random selection by inputting a quantity rather than a percentage. This lisp is a base that works well for percentages. I am aware this has been already asked.
(defun c:randset (/ ss sl i en el ep pct qty rs) ;; SMadsen Random Number (defun randnum (/ modulus multiplier increment random) (if (not seed) (setq seed (getvar "DATE"))) (setq modulus 65536 multiplier 25173 increment 13849 seed (rem (+ (* multiplier seed) increment) modulus) random (/ seed modulus))) (cond ((or (setq ss (ssget "i")) (setq ss (ssget))) (sssetfirst nil ss) (setq sl (sslength ss) i -1) (while (setq en (ssname ss (setq i (1+ i)))) (setq el (cons en el)))) (T (alert "\nNo Entities Found") (exit))) (initget 7) (setq pct (getreal "\nPercentage To Randomly Choose: ")) (setq qty (fix (* sl pct 0.01))) (setq rs (ssadd)) (while (> qty (sslength rs)) (setq ep (fix (* sl (randnum))) en (nth ep el)) (if (not (ssmemb en rs)) (ssadd en rs))) (sssetfirst nil rs) (princ) )
I found another forum where one user suggests to swap a part of the script.
Instead of this:
(setq pct (getreal "\nPercentage To Randomly Choose: ")) (setq qty (fix (* sl pct 0.01)))
do this:
(setq qty (geting "\nNumber of items to be selected: "))
I tried the swap but I get an no function definition error. I don't truly understand what I'm doing so if any of you has a solution that would be awesome. Feel free to redirect me if there is a more appropriate place to ask such questions.
As a sidenote I posted this on reddit but I'm thinking this here may be more appropriate.
Thanks
Solved! Go to Solution.