CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 5152

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))).
ACAD
100% *  CAD 
1.6.2001    18980×  
Prices - CAD eShop:
applies to: AutoCAD ·

See also:
Tip 14085:JavaScript API support in AutoCAD and AutoCAD LT.
Tip 14063:How to get week day and week number from a given date.
Tip 14061:Animated drawing of geometry in AutoCAD.
Tip 14056:How to move blocks in the Z axis to the terrain model surface?
Tip 14048:List of disks, CD-ROM drives, USBs and other disk functions for LISP.


Back   All CAD Tips



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   



Featuring:
Publish interactive 3D PDF models from AutoCAD, Inventor or Revit with Share3D More info


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist