scala中的字符串
Managing our research cluster, I frequently need to generate some string for new users’ password. How to generate them automatically and randomly in Scala? The passwords need characters ‘a’ – ‘z’, ‘A’ – ‘Z’ and ‘0’ – ‘9’ only.
在管理研究集群时,我经常需要为新用户的密码生成一些字符串 。 如何在Scala中自动随机生成它们? 密码仅需要字符“ a” –“ z”,“ A” –“ Z”和“ 0” –“ 9”。
This piece of code works very well for me:
这段代码对我来说非常有效:
def randomString(len: Int): String = {
val rand = new scala.util.Random(System.nanoTime)
val sb = new StringBuild