scala 使用BigInt创建随机文件字符串名称
scala BigInt加上util的Random可以创建一个BigInt的随机数,并且可以控制长度。
同时利用toString方法,可以转换成字符串。
需要注意的是
toString(x:Int) 方法在官方文档上面并么有后面的( x:Int ) 参数,在BigInt那一节是没有的。
x 代表转换成的位数(进制数)
如下所示
scala> BigInt.probablePrime(100,scala.util.Random)
res57: scala.math.BigInt = 1255891472355484063582457237603
scala> BigInt.probablePrime(100,scala.util.Random).toString(32)
res58: String = q01r387su2epnhudsv07
scala> BigInt.probablePrime(100,scala.util.Random).toString(2)
res59: String = 1101011001101111100010000100111011111000011001100100111010101110010100000001001101010101100100011011
scala> BigInt.probablePrime(100,scala.util.Random).toString(16)
res60: String = eb5d2a9d9795550f20de73a07
文章已经结束啦
文章版权:Postbird-There I am , in the world more exciting!
本文链接:http://www.ptbird.cn/scala-bigint-tostring.html
转载请注明文章原始出处 !
扫描二维码,在手机阅读!