Rand Number lisp

Rand Number lisp

gccdaemon
Collaborator Collaborator
1,712 Views
9 Replies
Message 1 of 10

Rand Number lisp

gccdaemon
Collaborator
Collaborator

I'm looking for a routine that will return a randomized number from 0 to 99. I'm trying to make a fun routine for april fools day! I will post the code when finished. 🙂

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Accepted solutions (1)
1,713 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Do a Search.  There are several of those on these Forums, some of which return a random number between 0 and 1, from which you could just multiply the result by 99.

Kent Cooper, AIA
Message 3 of 10

gccdaemon
Collaborator
Collaborator

I did see that one on AFRALISP, but didn't think to set my own multiplier.

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Message 4 of 10

hmsilva
Mentor
Mentor
Accepted solution

Hi Andrew,

 

try Lee Mac's LM:rand and LM:randrange...

 

Hope this helps,
Henrique

EESignature

Message 5 of 10

Lee_Mac
Advisor
Advisor
hmsilva wrote:

Hi Andrew,

 

try Lee Mac's LM:rand and LM:randrange...

 

Hope this helps,
Henrique

 

Thank you for the recommendation Henrique!

Message 6 of 10

hmsilva
Mentor
Mentor

You're welcome, Lee!

Henrique

EESignature

0 Likes
Message 7 of 10

gccdaemon
Collaborator
Collaborator

Here it is. It's pretty simple and good for a chuckle. I may revise it later to have really bad jokes...lol.

 

Thanks for everyones help. Had trouble with the number coming out of the random range, but RTOSsed it for a win.

 

(defun C:AF nil (C:AFFIRMATION))
(defun C:AFFIRM nil (C:AFFIRMATION))
(defun C:AFFIRMATION ( / num )
	(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)
	)
	(defun LM:randrange ( a b )
		(+	(min a b)	(fix (* (LM:rand) (1+ (abs (- a b))))))
	)
	(SETQ num (rtos (LM:randrange 0 99)))
	(cond	((= num "1")	(alert	"I feel the love of those who are not physically around me."))
		((= num "2")	(alert	"I take pleasure in my own solitude."))
		((= num "3")	(alert	"I am too big a gift to this world to feel self-pity."))
		((= num "4")	(alert	"I love and approve of myself."))
		((= num "5")	(alert	"I focus on breathing and grounding myself."))
		((= num "6")	(alert	"Following my intuition and my heart keeps me safe and sound."))
		((= num "7")	(alert	"I make the right choices every time."))
		((= num "8")	(alert	"I draw from my inner strength and light."))
		((= num "9")	(alert	"I trust myself."))
		((= num "10")	(alert	"I am a unique child of this world."))
		((= num "11")	(alert	"I have as much brightness to offer the world as the next person."))
		((= num "12")	(alert	"I matter and what I have to offer this world also matters."))
		((= num "13")	(alert	"I may be one in 7 billion but I am also one in 7 billion."))
		((= num "14")	(alert	"I trust my inner wisdom and intuition."))
		((= num "15")	(alert	"I breathe in calmness and breathe out nervousness."))
		((= num "16")	(alert	"This situation works out for my highest good."))
		((= num "17")	(alert	"Wonderful things unfold before me."))
		((= num "18")	(alert	"I forgive myself for all the mistakes I have made."))
		((= num "19")	(alert	"I let go of my anger so I can see clearly."))
		((= num "20")	(alert	"I accept responsibility if my anger has hurt anyone."))
		((= num "21")	(alert	"I replace my anger with understanding and compassion."))
		((= num "22")	(alert	"I offer an apology to those affected by my anger."))
		((= num "23")	(alert	"I may not understand the good in this situation but it is there."))
		((= num "24")	(alert	"I muster up more hope and courage from deep inside me."))
		((= num "25")	(alert	"I choose to find hopeful and optimistic ways to look at this."))
		((= num "26")	(alert	"I kindly ask for help and guidance if I cannot see a better way."))
		((= num "27")	(alert	"I refuse to give up because I haven’t tried all possible ways."))
		((= num "28")	(alert	"I know my wisdom guides me to the right decision."))
		((= num "29")	(alert	"I trust myself to make the best decision for me."))
		((= num "30")	(alert	"I receive all feedback with kindness but make the final call myself."))
		((= num "31")	(alert	"I listen lovingly to this inner conflict and\nreflect on it until I get to peace around it."))
		((= num "32")	(alert	"I love my family even if they do not understand me completely."))
		((= num "33")	(alert	"I show my family how much I love them in all\nthe verbal and non-verbal ways I can."))
		((= num "34")	(alert	"There is a good reason I was paired with this perfect family."))
		((= num "35")	(alert	"I choose to see my family as a gift."))
		((= num "36")	(alert	"I am a better person from the hardship that\nI’ve gone through with my family."))
		((= num "37")	(alert	"I choose friends who approve of me and love me."))
		((= num "38")	(alert	"I surround myself with people who treat me well."))
		((= num "39")	(alert	"I take the time to show my friends that I care about them."))
		((= num "40")	(alert	"My friends do not judge me,\nnor do they influence what I do with my life."))
		((= num "41")	(alert	"I take great pleasure in my friends,\neven if we disagree or live different lives."))
		((= num "42")	(alert	"I am beautiful and smart and that’s how everyone sees me."))
		((= num "43")	(alert	"I take comfort in the fact that I can always leave this situation."))
		((= num "44")	(alert	"I never know what amazing incredible person I will meet next."))
		((= num "45")	(alert	"The company of strangers teaches me\nmore about my own likes and dislikes."))
		((= num "46")	(alert	"I am doing work that I enjoy and find fulfilling."))
		((= num "47")	(alert	"I play a big role in my own career success."))
		((= num "48")	(alert	"I ask for and do meaningful, wonderful and rewarding work."))
		((= num "49")	(alert	"I engage in work that impacts this world positively."))
		((= num "50")	(alert	"I believe in my ability to change the world with the work that I do."))
		((= num "51")	(alert	"Peaceful sleep awaits me in dreamland."))
		((= num "52")	(alert	"I let go of all the false stories I make up in my head."))
		((= num "53")	(alert	"I release my mind of thought until the morning."))
		((= num "54")	(alert	"I embrace the peace and quiet of the night."))
		((= num "55")	(alert	"I sleep soundly and deeply and beautifully into this night."))
		((= num "56")	(alert	"This day brings me nothing but joy."))
		((= num "57")	(alert	"Today will be a gorgeous day to remember."))
		((= num "58")	(alert	"My thoughts are my reality so I think up a bright new day."))
		((= num "59")	(alert	"I fill my day with hope and face it with joy."))
		((= num "60")	(alert	"I choose to fully participate in my day."))
		((= num "61")	(alert	"I let go of worries that drain my energy."))
		((= num "62")	(alert	"I make smart, calculated plans for my future."))
		((= num "63")	(alert	"I am a money magnet and attract wealth and abundance."))
		((= num "64")	(alert	"I am in complete charge of planning for my future."))
		((= num "65")	(alert	"I trust in my own ability to provide well for my family."))
		((= num "66")	(alert	"I follow my dreams no matter what."))
		((= num "67")	(alert	"I show compassion in helping my loved ones understand my dreams."))
		((= num "68")	(alert	"I ask my loved ones to support my dreams."))
		((= num "69")	(alert	"I answer questions about my dreams without getting defensive."))
		((= num "70")	(alert	"My loved ones love me even without fully grappling with my dreams."))
		((= num "71")	(alert	"I accept everyone as they are and continue on with pursuing my dream."))
		((= num "72")	(alert	"I am safe and sound. All is well."))
		((= num "73")	(alert	"Everything works out for my highest good."))
		((= num "74")	(alert	"There is a great reason this is unfolding before me now."))
		((= num "75")	(alert	"I have the smarts and the ability to get through this."))
		((= num "76")	(alert	"All my problems have a solution."))
		((= num "77")	(alert	"I attempt all – not some – possible ways to get unstuck."))
		((= num "78")	(alert	"I seek a new way of thinking about this situation."))
		((= num "79")	(alert	"The answer is right before me, even if I am not seeing it yet."))
		((= num "80")	(alert	"I believe in my ability to unlock the way and set myself free."))
		((= num "81")	(alert	"I have no right to compare myself to anyone\nfor I do not know their whole story."))
		((= num "82")	(alert	"I compare myself only to my highest self."))
		((= num "83")	(alert	"I choose to see the light that I am to this world."))
		((= num "84")	(alert	"I am happy in my own skin and in my own circumstances."))
		((= num "85")	(alert	"I see myself as a gift to my people and community and nation."))
		((= num "86")	(alert	"I am more than good enough and I get better every day."))
		((= num "87")	(alert	"I give up the habit to criticize myself."))
		((= num "88")	(alert	"I adopt the mindset to praise myself."))
		((= num "89")	(alert	"I see the perfection in all my flaws and all my genius."))
		((= num "90")	(alert	"I fully approve of who I am, even as I get better."))
		((= num "91")	(alert	"I am a good person at all times of day and night."))
		((= num "92")	(alert	"I cannot give up until I have tried every conceivable way."))
		((= num "93")	(alert	"Giving up is easy and always an option\nso let’s delay it for another day."))
		((= num "94")	(alert	"I press on because I believe in my path."))
		((= num "95")	(alert	"It is always too early to give up on my goals."))
		((= num "96")	(alert	"I must know what awaits me at the end of this rope\nso I do not give up."))
		((= num "97")	(alert	"The past has no power over me anymore."))
		((= num "98")	(alert	"I embrace the rhythm and the flowing of my own heart."))
		((= num "99")	(alert	"All that I need comes to me at the right time\nand place in this life."))
		((= num "0")	(alert	"I am deeply fulfilled with who I am."))
	)
	(PRINC)
)
(PRINC "Type \"AF\", \"AFFIRM\", or \"AFFIRMATION\" to help soothe your soul.")

 

HAPPY APRIL FOOLS DAY!

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 8 of 10

dbroad
Mentor
Mentor

You could have saved a bit of code if you just had a list of sayings

 

(setq mysayings (list "saying1" "saying2" "etc"))

(alert (nth (LM:randrange 0 (length mysayings)) mysayings))
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 9 of 10

gccdaemon
Collaborator
Collaborator

I had considered that but for me it was just as easy to do because my list was already numbered. All I had to do was find/replace for the COND to be ready...lol. Thanks for the option though!

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@gccdaemon wrote:

I had considered that but for me it was just as easy to do because my list was already numbered. ....


Even there, you could save a whole batch of code characters by using the random number as a number instead of converting it to text [eliminating the (rtos) and the quotation marks in all the (cond) tests], and by having just one (alert) function, and putting the (cond) inside it, rather than having individual (alert) functions within every condition separately:

....

  (SETQ num (LM:randrange 0 99))

  (alert

    (cond

      ((= num 1) "I feel the love of those who are not physically around me.")
      ((= num 2) "I take pleasure in my own solitude.")
      ((= num 3) "I am too big a gift to this world to feel self-pity.")

....

Kent Cooper, AIA
0 Likes