{"id":5168,"date":"2021-03-06T19:01:18","date_gmt":"2021-03-06T11:01:18","guid":{"rendered":"https:\/\/www.highflybird.com\/blog\/?p=5168"},"modified":"2025-12-08T00:34:49","modified_gmt":"2025-12-07T16:34:49","slug":"lisp%e7%9a%84%e9%9a%8f%e6%9c%ba%e5%87%bd%e6%95%b0%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.highflybird.com\/blog\/?p=5168","title":{"rendered":"LISP\u7684\u968f\u673a\u51fd\u6570\u7684\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u5bf9Autolisp\u6765\u8bf4\uff0c\u6ca1\u6709\u751f\u6210\u968f\u673a\u6570\u7684\u51fd\u6570\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u6709\u5982\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u4ea7\u751f\u5b83\uff1a<\/p>\n\n\n\n<p>\u65b9\u6cd5\u4e00\uff1a\u7528\u540c\u4f59\u51fd\u6570\u5b9e\u73b0\uff0c\u8fd9\u662f\u7eafLISP\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">;;;rand function-some code from Lee Mac,--thanks.\n(defun LM:random (Var \/ x)\n  (\/ (setq x    4294967296.0\n       seed (rem (1+ (* 1664525.0\n                (cond (seed)\n                  ((getvar var))\n                )\n             )\n             )\n             x\n        )\n     )\n     x\n  )\n)\n(defun Rand (a b var)\n  (fix (+ a (* (LM:random var) (- b a -1))))\n)\n<\/pre>\n\n\n\n<p>\u65b9\u6cd5\u4e8c\uff1a\u7528\u7cfb\u7edf\u7684\u76f8\u5173\u7684\u53d8\u91cf\u5982cputicks,TDUSRTIMER\u7b49\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<p>\u6b64\u65b9\u6cd5\u53ef\u80fd\u4f1a\u4ea7\u751f\u4e00\u4e9b\u4e0d\u662f\u5f88\u968f\u673a\u7684\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(defun c:random    ()\n  (setq seed (getvar \"TDUSRTIMER\"))\n  (setq seed (- seed (fix seed)))\n  (rem (* seed 86400) 1)\n)\n<\/pre>\n\n\n\n<p>\u65b9\u6cd5\u4e09\uff1a\u5229\u7528windows\u7cfb\u7edfcom\u4e2d\u4ea7\u751f\u968f\u673a\u6570\u3002<\/p>\n\n\n\n<p>\u5f53\u524d\u5b9e\u73b0Random\u7c7b\u57fa\u4e8e Donald E.Knuth \u5220\u51cf\u968f\u673a\u6570\u751f\u6210\u5668\u7b97\u6cd5\u7684\u4fee\u6539\u7248\u672c\u3002 \u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 D.e\u3002 Knuth\u3002 \u8ba1\u7b97\u673a\u7f16\u7a0b\uff0c\u5377 2 \u7684\u6280\u672f\uff1aSeminumerical \u7b97\u6cd5\u3002 Addison-wesley\uff0cReading\uff0cMA\uff0c\u7b2c\u4e09\u4e2a\u7248\u672c\uff0c1997\u5e74\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  (setq rndObj (vlax-create-object \"System.Random\"))\n  (setq x (vlax-invoke rndobj 'nextdouble))\n  (setq y (vlax-invoke rndobj 'next))\n\n  (defun sysRnd (x y)\n    (+ x (* (vlax-invoke rndobj 'nextdouble) (- y x)))\n  )\n<\/pre>\n\n\n\n<p>\u65b9\u6cd5\u56db\uff1a\u7528vbscript \u6216\u8005Jscirpt\u7b49\u5185\u90e8\u7684\u968f\u673a\u51fd\u6570\u4ea7\u751f\uff0c\u7136\u540e\u5728lisp\u7528\u8c03\u7528\u811a\u672c\u8bed\u8a00\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  (if\n    (or\n      (setq wcs (vlax-create-object   \"Aec32BitAppServer.AecScriptControl.1\"))\n      (setq wcs (vlax-create-object \"ScriptControl\"))\n    )\n    (vlax-put-property wcs \"language\" \"VBScript\")\n  )\n  (setq str \"Randomize\n             Function Rand(x,y)\\n\n                 Rand=x+Rnd*(y-x)\\n\n             End Function\"\n  )        \n  (vlax-invoke wcs 'addcode str)\n\n  (defun wcsRnd(a b)\n    (vlax-invoke wcs 'run \"rand\" a b)\n  )\n<\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u7ecf\u8fc7\u6d4b\u8bd5\u9a8c\u8bc1\uff0c\u7528\u540c\u4f59\u7684\u901f\u5ea6\u6700\u5feb\uff0cvbs\u6700\u6162\uff0csystem.random\u4e2d\u95f4\uff0c\u4f46\u540c\u4f59\u6cd5\u7684\u6548\u7387\u5e76\u672a\u8d85\u8fc7system.random\u5f88\u591a\uff0c\u4ec5\u4ec5\u662f\u51e0\u500d\u7684\u5dee\u8ddd\u3002\u800csystem.random\u867d\u4e5f\u662f\u4f2a\u968f\u673a\u7684\uff0c\u4f46\u662f\u6b63\u786e\u6027\u6bd4\u540c\u4f59\u6cd5\u9ad8\u3002<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9Autolisp\u6765\u8bf4\uff0c\u6ca1\u6709\u751f\u6210\u968f\u673a\u6570\u7684\u51fd\u6570\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u6709\u5982\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u4ea7\u751f\u5b83\uff1a \u65b9\u6cd5\u4e00\uff1a\u7528\u540c\u4f59\u51fd\u6570\u5b9e\u73b0\uff0c\u8fd9\u662f\u7eaf<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/www.highflybird.com\/blog\/?p=5168\" class=\"themebutton2\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-5168","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5168"}],"version-history":[{"count":13,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5168\/revisions"}],"predecessor-version":[{"id":5239,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5168\/revisions\/5239"}],"wp:attachment":[{"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highflybird.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}