本帖最后由 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))
- )
- (setq idx (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))))
|