Do you known the function that return a random number ?

a107

Usenet Archive
Joined
Dec 20, 2003
Messages
1
Reaction score
0
Dear you,

I have only one question but I haven’t got the anwser So I think you can help me. The question is a function that return a random number in Autolisp. In the catalogue funtions I can’t find it. Hoping you can help me or show me the way to solve it ?.

Thank so much.
 
a107 said:
Dear you,

I have only one question but I haven?t got the anwser So I think yo u can help me. The question is a function that return a random number in Au tolisp. In the catalogue funtions I can?t find it. Hoping you can h elp me or show me the way to solve it ?.

Thank so much.

To generate random number you can try to use last digits of system variable "cdate". These are hundredths of a second of current time. (of course if they are not generated several times in your procedure)
J.B.
 
There isn't one, per se. What many folks do is to create a little function that uses the always-changing CDATE variable..
___

Dear you,

I have only one question but I haven't got the anwser So I think you can help me. The question is a function that return a random number in Autolisp. In the catalogue funtions I can't find it. Hoping you can help me or show me the way to solve it ?.

Thank so much.
 
Hi a107

This is based on the logistic equation
p = p + rp(1-p)
by the Belgiamn mathematician Pierre Francois Verhulst. It is used to simulate population models in chaos theory.

Normaly I use C++ to do calculation which can't easily be done in Vlisp.

Anyway,
11.139323343 -> this can be another number of your choice
1.13579 -> this can be another number of your choice Be careful with these numbers, otherwise you'll get overflow The numbers returned are not "tue" random numbers.

(setq rnumber (random))

;;; returns a random nunber between 0 and 1
(defun random ( / rk a c )
(st)
(setq rk seed
a (- 11.139323343 seed)
c (+ 1.13579 seed)
rk (/ (+ (* a rk) c) 2))

(repeat 10 ;;; can be 20 as well
(setq rk (/ (+ (* a rk) c) 2)
rk (- rk (fix rk)));;; the random number between 0 and 1 ) rk;;; the ranom number );;; end defun

;;; need a seed
(defun st ( / start-t)
(setq start-t (getvar "Date");;; get timer
seed (- start-t (fix start-t)));;; seed for random number )

Regards
Dieter
 
(defun rand (rem (fix (* 100000000 (getvar "TDINDWG"))) 10))

If I remember correctly, the PC clock only updates 18 times per second. With today's hardware, this can be an issue if you need to generate random numbers with any kind of frequency. -David
 
using the timer isn't random ! As you stated its repeated 18 times per second! The logistic function is pseudo eg not truly random but quite near.

Regards
Dieter
 
That's incorrect. It is *not* "repeated" 18 times per second, it is
*updated* 18 times per second, and every value is different. There's a huge difference between "repeated" and "updated." For most purposes, the inability to control the point in the update cycle at which a value is extracted makes the function for practical purposes "random." ___
 
which makes it cyclic.
The value returned is *updated* at 1/18 const intervall points If the update intervall would be variable we would be closer to random.
 
In actual practice, if your program needs only one pseudo-random number, cdate may be good enough. But if you need to generatel a lot of numbers, the cyclical nature of the update makes cdate unusable. Whatever you're calculating, whatever the speed of your machine, there will be an obviously non-random pattern in the numbers you get. Try it and see! I use a function similar to that cited earlier, with different constants.
 
that's what I wanted to make clear.

A random number is an arbitrary number, but an arbitrary number is not a random number!

Regards
Dieter
 

Latest threads

Back
Top