分享一个生成随机字符串的源码
本帖最后由 baitang36 于 2024-10-30 16:22 编辑(DEFUN make_rnd_string (/ lvar0lvar1 lvar2 lvar3 lvar4lvar5 lvar6
lvar7 lvar8 lvar9)
(setqlvar1
(LIST "{" "}" "~" "[" "]" "_" "^" "*" "$" ":" "#" "@")
)
(setqlvar2
(LIST "s" "t" "u" "1" "2" "3" "4" "5" "6"
"?" "#" "@" "[" "]" "_" "^" "{" "}"
"r" "x" "y" "h" "i" "w" "c" "d" "k"
"~" "*" "$" ":" "l" "m" "v" "g" "q"
"p" "z" "n" "o" "a" "e" "f" "j" "b"
"7" "8" "9" "0"
)
)
(setqlvar8 (list "j" "b""s" "w" "c" "d""k" "p"
"z" "n""l" "m" "t" "u""h" "i"
"v" "g""q" "r" "x" "y""o" "a"
"e" "f"
)
)
(setqlvar3 (rem (READ (SUBSTR (VL-STRING-SUBST
""
"."
(RTOS (GETVAR "cputicks") 2 16)
)
12
2
)
)
12
)
)
(setqlvar4 (rem (READ (SUBSTR (VL-STRING-SUBST
""
"."
(RTOS (GETVAR "cputicks") 2 16)
)
12
2
)
)
48
)
)
(setqlvar5 (rem (READ (SUBSTR (VL-STRING-SUBST
""
"."
(RTOS (GETVAR "cputicks") 2 16)
)
12
2
)
)
48
)
)
(setqlvar6 (rem (READ (SUBSTR (VL-STRING-SUBST
""
"."
(RTOS (GETVAR "cputicks") 2 16)
)
12
2
)
)
48
)
)
(setq lvar0 (rem (/ (getvar "millisecs") 10000) 26))
(setq lvar9 (rem (getvar "millisecs") 26))
(if (= nil lvar3)
(setq lvar3 1)
)
(if (= nil lvar4)
(setq lvar4 2)
)
(if (= nil lvar5)
(setq lvar5 3)
)
(if (= nil lvar6)
(setq lvar6 4)
)
(setqlvar7
(STRCAT
(NTH lvar0 lvar8)
(NTH lvar3 lvar1)
(NTH lvar4 lvar2)
(NTH lvar5 lvar2)
(NTH lvar6 lvar2)
(NTH lvar9 lvar8)
)
)
(if (VL-POSITION
lvar7
rnd_string_list
)
(PROGN (setq lvar7 (make_rnd_string)))
(PROGN (setq rnd_string_list
(CONS
lvar7
rnd_string_list
)
)
lvar7
)
)
)
(DEFUN make_rnd_string12 ()
(strcat (make_rnd_string) (make_rnd_string))
)
;rnd_string_list 是全局变量,保存已有的字符串,防止重复
用法:加载后(make_rnd_string)生成一个6字节字符串。
(make_rnd_string12)生成12字节字符串
kozmosovia 发表于 2024-10-31 10:24
随机质量差的很
要感谢盛老师分享,如果有更好的可以发出来,也是个思路,倒不必这样说。 本帖最后由 kozmosovia 于 2024-10-31 16:55 编辑
不算随机数的生成随机字符串(Defun RandomStr (len / _Core IDX PWD RTN TXT)
(Defun _Core ()
;;;; GUID只保留数字
(vl-list->string
(vl-remove-if-not
(function (lambda (x) (< 47 x 58)))
(vl-string->list
(vlax-get (vlax-create-object "Scriptlet.TypeLib") "GUID")
)
)
)
)
;;; 生成ASCII=48~122的所有字符
(setq idx 47)
(while (<= (setq idx (1+ idx)) 122)
(setq pwd (cons (chr idx) pwd))
)
;;; 去除不需要的特殊字符
(foreach abc '("/" "[" "]" "=" ":" ";" "`" "^" "\\" "?" ">" "<" "@")
(setq pwd (vl-remove abc pwd))
)
(setqidx (length pwd)
txt (_Core)
rtn ""
)
;;;利用GUID创建长度为(4*指定长度)的数字字符串
(while (< (strlen txt) (* 4 len))
(setq txt (strcat txt (_Core)))
)
(repeat len
;;;每4个数字转成<9999的整数对字符表长度取模,根据模数据提取对应的字符
(setq rtn (strcat rtn
(nth (rem (atoi (substr txt 1 4)) idx)
pwd
)
)
txt (substr txt 5)
)
)
rtn
)
(repeat 11 (princ (strcat "\n " (RandomStr 20))))
本帖最后由 baitang36 于 2024-10-31 15:19 编辑
kozmosovia 发表于 2024-10-31 10:24
随机质量差的很
你没仔细看程序,第一个字母是每10秒换一次,第6个字符是1毫秒换一次。这是故意这么做的。
发布源码的目的是授人以渔,代码本身没多少技术含量,喜欢的人可以随意改,不喜欢无视即可。
你可以随意改自己不满意的地方。
猫老师也写过这个,代码如果发出来会吓着你的。
tryhi问为什么重复的内容不改成一个函数,也是为了这个,你可以随意去修改它。
感谢大佬分享 是否有实例? 不如leemac版本
https://lee-mac.com/password.html 我顶顶顶顶顶一下:sleepy: lvar3、lvar4、lvar5、lvar6都是一样的代码,怎么不用一个函数 谢谢盛老师分享。 tryhi 发表于 2024-10-30 16:47
lvar3、lvar4、lvar5、lvar6都是一样的代码,怎么不用一个函数
为改起来方便 kozmosovia 发表于 2024-10-30 16:41
不如leemac版本
https://lee-mac.com/password.html
研究一下lm的优点,加到这个代码里面? 盛老师,给一个demo呀~
页:
[1]
2