注册 登录
明经CAD社区 返回首页

soly2006的个人空间 http://www.mjtd.com/?351467 [收藏] [复制] [分享] [RSS]

日志

[自定义函数]给定返回类型(整数或实数)和随机区间,返回一个数值

热度 3已有 1629 次阅读2012-2-7 12:15 |系统分类:开发| 随机函数

;; | ---------------------------------------------------------------------------
;; | jn-rand
;; | ---------------------------------------------------------------------------
;; | Function : 给定返回类型(整数或实数)和随机区间,返回一个数值
;; | Argument : (jn-rand 1 45.3 46.7)或(jn-rand 0 45.3 46.7),返回类型标志为0或其他
;; | Returns  : 随机数,在上下限间
;; | Updated  : 2012-2-7
;; | e-mail   : soly2006@qq.com
;; | qq       : 408525383
;; | ---------------------------------------------------------------------------
(defun jn-rand(flag1 lowlmt toplmt / seed0 seed1 r1 r2) ;标志,上下限
(setq seed0 (getvar "cputicks")) ;取得当前CPU的运行频率e.g.(CPUTICKS = 3658253708571.000 (只读))
(if (= flag1 0)    ;如果是整数(FLAG1=0)
(progn
(setq SEED1 (atoi (substr (rtos seed0) 8 2))) ;取其中的两个数位
(princ seed1)
(setq r1 (/ seed1 100.000))  ;取得百分比
 (setq r2 (fix (+ lowlmt (* (- toplmt lowlmt) r1))))
)
(progn
(setq SEED1 (atof (substr (rtos seed0) 8 2))) ;取其中的两个数位
(setq r1 (/ seed1 100.000))  ;取得百分比
(setq r2 (+ lowlmt (* (- toplmt lowlmt) r1)))
))
)


路过

雷人
2

握手

鲜花

鸡蛋

刚表态过的朋友 (2 人)

发表评论 评论 (2 个评论)

回复 llsheng_73 2015-8-25 11:44
(defun rand(low top / a b)
  (setq a(last(assoc(type low)'((int atoi)(real atof))))
        b(+(*(- top low)(/(apply a(list(substr(rtos(getvar "cputicks"))8 3)))1000.))low)
        b(if(equal a'atoi)(fix b)b))
  )
回复 soly2006 2015-9-14 13:47
llsheng_73: (defun rand(low top / a b)
  (setq a(last(assoc(type low)'((int atoi)(real atof))))
        b(+(*(- top low)(/(apply a(list(substr(rtos(getvar "cputic ...
师兄就是牛逼

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 09:23 , Processed in 0.082831 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部