;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; Copyright (c) Jun. 1996 by Takehiko Nagakura. ;;;; ;;;; All rights reserved. ;;;; ;;;; ;;;; ;;;; Do not copy, use, modify or distribute this software ;;;; ;;;; without written permission by Nagakura. Nagakura will ;;;; ;;;; not be responsible for any consequence of its use. ;;;; ;;;; ;;;; ;;;; Takehiko Nagakura (e-mail: takehiko@mit.edu) ;;;; ;;;; Massachusetts Institute of Technology ;;;; ;;;; 77 Massachusetts Ave. 10-472M, Cambridge, MA 02139 ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Last updated Feb 28, 2005 by TN for true color sample ;;;; Last updated Dec 29, 1996 by TN ;; The following pseudo-random number generator was ;; adopted from Kernighan and Ritchie's "C Programming Language" ;; second edition, p46. ;; If you want to use a random number in your program, you can just ;; copy this whole program into your program and use the function, ;; (rand min max) ;; as described below. It works, but do not ask me why this code ;; can generate fairly good randomness. If you are curious ;; to know it, some discussion on peudo-random number generator ;; is found in Paul Kohut's web page, ;; http://xarch.tu-graz.ac.at/~rurban/news/comp.cad.autocad/rand.lsp.html. ;; functions and their descriptions ;; ;; (rand16) : generates a random number between 1 and 32767, ;; that is, a positive 16 bit integer ;; (rand min max) : generates a random number between min and max. ;; Min and max must be an integer between 0 and 32767. ;; (c:demo) : demo function to generate random points (setq *SeedRand* nil) ; initialize the global ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun rand16 ( / s ) ; when this is used for the first time, initialize the seed ; from the system clock. (if (null *SeedRand*) (progn (setq s (getvar "date")) (setq *SeedRand* (fix (* 86400 (- s (fix s))))) ) ; progn ) ; if ; To generate a psudo-sandom number sequence ; I use the routine described in Kernighan and Ritchie's ; "C Programming Language" second edition, p46 (setq *SeedRand* (+ (* *SeedRand* 1103515245) 12345)) ; trim off the bits left of the 16th bits (logand (/ *SeedRand* 65536) 32767) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; generates a random number between min and max. ; min and max must be a non-negative integer smaller than 32678. (defun rand (min max / r16 range quotient remainder result) (setq r16 (rand16)) ; random number smaller than 32678 (setq range (+ 1 (- max min))) ; number of integers to be produced (setq quotient (/ r16 range)) ; result in non-neg. integer (setq remainder (- r16 (* quotient range))) (setq result (+ min remainder)) result ) ; test it ; (rand 5 7) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:demo ( / x y n) (command "plan" "") (command "cmdecho" 0) (command "zoom" "window" (list -10000 -10000) (list 40000 40000)) (command "pdmode" 65) (command "pdsize" -2) (repeat 500 (setq x (rand16) ) (setq y (rand16)) (command "point" (list x y )) ;AutoCAD takes color numbers between 1 and 255 (setq n (rand 1 255)) (command "chprop" (entlast) "" "color" n "") ;(print (list x y n)) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:demo2 ( / x y n) (command "plan" "") (command "cmdecho" 0) (command "zoom" "window" (list -10000 -10000) (list 40000 40000)) (command "pdmode" 65) (command "pdsize" -2) (repeat 500 (setq x (rand16) ) (setq y (rand16)) (command "point" (list x y )) ;AutoCAD true color uses numbers between 1 and 255 for rgb channels ;I use 100-160 range to make pastel colors. (setq r (rand 100 160)) (setq g (rand 100 160)) (setq b (rand 100 160)) (command "chprop" (entlast) "" "color" "truecolor" (strcat (itoa r) "," (itoa g) "," (itoa b) ) "") ;(print (list x y n)) ))