Kowal Posted March 4, 2016 Share Posted March 4, 2016 Dear Lee, Your code is a great. But for intervals of negative shifts period by one. (LM:randrange 1 3) 1 1 1 2 1 3 3 1 2 3 (LM:randrange -3 -1) -1 -2 -1 -2 0 0 0 -2 0 -1 Of course, I can use a range of positive and negative transform him. I can also change the signs on the negative. Please explain. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 4, 2016 Share Posted March 4, 2016 (edited) Please try the following [untested] modification: ;; Random in Range - Lee Mac ;; Returns a pseudo-random integral number in a given range (inclusive) (defun LM:randrange ( a b ) (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))) ) EDIT: Updated. Edited March 4, 2016 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 5, 2016 Share Posted March 5, 2016 I have now also updated the function on my site: Random in Range Quote Link to comment Share on other sites More sharing options...
Kowal Posted March 6, 2016 Author Share Posted March 6, 2016 Thanks for the update. Sorry for my poor English language. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2016 Share Posted March 6, 2016 You're welcome Kowal, there is no need to apologise. Quote Link to comment Share on other sites More sharing options...
oberkarl Posted July 31, 2023 Share Posted July 31, 2023 Hey Lee, I ran into a problem with your random number generator as I attempted to use it in my acaddoc.lsp file. Because it seeds off the Date variable, the value is not random between opening files as they all begin at the same seed. each day. I was able to solve this by replacing your use of "getvar Date" with the MILLISECS variable and parsing it effectively to pull out the constantly changing base numbers. I now am able to successfully generate random numbers effectively in all use cases. I'm curious if you have encountered this problem before or may have a more elegant solution. Thanks! (setq old (rtos (getvar "MILLISECS") 2 0)) (setq new "") (repeat (setq i (strlen old)) (setq new (strcat new (substr old i 1)) i (1- i) ) ) (setq new (substr new 1 4)) (setq seed (atof new)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.