如何在clojure中生成随机字母数字字符串?

我一直在尝试编写一个脚本,该脚本创建一个包含 20 个字母的随机字母数字并将其附加到链接的末尾。我坚持制作字母数字。任何帮助,将不胜感激!

回答

(apply str (repeatedly 20 #(rand-nth "abcdefghijklmnopqrstuvwxyz0123456789")))

  • there is no reason to prefer `reduce str` over `apply str` here. moreover `reduce str` is dramatically slower, since it leads to the creation of multiple obsolete StringBuilder instances, instead of one instance with `apply`. see the [source](https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L544)

以上是如何在clojure中生成随机字母数字字符串?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>