CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products []
Cesky English Deutsch
 Visitors: 5676 

CAD tip CAD tip # 1366:

Question CAD 
 %  platform  category 
Q - question

How to generate a random number using AutoLISP?

A - answer Use the following function for a LISP generator of pseudo-random numbers:
(defun rnd (/ 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)
Each call of the function (rnd) then returns a pseudo-random number in the range (0,1). E.g. to get random integers from 0 to 20, use (fix(* 20 (rnd))).
100% *  CAD 
1.6.2001    13145×  
Comments   Tell a friend
applies to: AutoCAD ·

See also:
Tip 11780:How to rename layouts by a specific attribute of the title block?
Tip 11751:toMulti converts polylines to multi-lines driven by a definition table.
Tip 11726:Loading 3D models in the OBJ file format to AutoCAD.
Tip 11714:How to assign a RAL color to a DWG object and get its ACI equivalent?
Tip 11693:Adding numbers in drawing texts.

Back   All CAD Tips All CAD tips&tricks

How to make a PDF file from your drawing? « | » Where to find a library of traffic signs for AutoCAD?

Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   

Extend your AutoCAD LT productivity with our popular add-on
CADstudio LT Extension More info

Please use these tips at your own risk.
CAD Studio (Xanadu) is not responsible for possible problems that may occur as a result of using any of these tips.