🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
使用示例: (random 0.1) ;;结果 0.0614254 (random 999) ;;结果 597 (random -999.999) ;;结果 -392.226 代码: ``` ;;; by Serge Pashkov: ;;; This is a multiplicative generator named ;;; URAND (Universial RANDom generator) with period length 2^31 and ;;; small value of the explicit correlations (though every ;;; multiplicative generator suffers from them in more and less ;;; extent). max seed: \*max-int\*, These numbers are fine for 32-bit ;;; ints. ;;;From a file by Reini Urban - simplified ;;;Comments by Reini Urban (defun random1 (/ seed) (setq seed \*RANDOM-SEED\*) (if (minusp (setq seed (+ 453816693 (\* seed 843314861)))) ;; hint: divide 2^31 as 2^30+2^30 (setq seed (+ seed 1073741824 1073741824))) (\* 4.656612873077392E-10 (setq \*RANDOM-SEED\* seed))) ;;; multiplicative rand (defun random (n) (cond ((\= 'int (type n)) (abs (fix (\* n (random1))))) ((numberp n) (\* n (random1))) (t (random1)))) ;;; Some generators require a special seed range. ;;; std-%get-internal-run-time will return a number between 0 and ;;; something like 86400000. (\* 24 60 60 1000) ;;; But we avoid integer overflows before calculating random, ;;; because we have no exceptions before R15. ;;; Constants: (setq \*MAX-LONGINT\* 2147483647) ; signed longint, 32-bit (setq \*MAX-SHORTINT\* 32767) ; signed shortint,16-bit (setq \*MAX-INT\* (IF (minusp (1+ \*max-shortint\*)) \*MAX-LONGINT\* \*MAX-SHORTINT\*)) (defun MilliSecInt() (fix (rem (fix (\* 86400000 (\- (getvar "date")(fix (getvar "date"))))) \*max-int\*))) (setq \*RANDOM-SEED\* (millisecint)) ```