1,rand(999999) 生成 6 位随机数
2,puts rand(0xffffff) # 十六进制的
3,puts rand 生成 0-1 之间的任意数
4, def newpass( len )
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
newpass = ""
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
puts newpass(15)
ref:
http://snippets.dzone.com/posts/show/491
http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby
posted on 2009-03-27 19:13
fl1429 阅读(8272)
评论(5) 编辑 收藏
评论:
# re: ruby 生成随机数 和 随机字符串
2010-01-02 04:32 |
# re: ruby 生成随机数 和 随机字符串
2010-03-31 10:58 |
This would be really simply to add the hot topic about this good post with support of article submission, but some time customers select free article submission. Hence I don’t get know what should be best of all.
回复 更多评论
# re: ruby 生成随机数 和 随机字符串
2010-10-21 14:56 |
I do guess that this is viable to go to this web page, because only here we should notice the nice topic related to this post. Thence, the dissertation writing service will take that for thesis sample writing.
回复 更多评论
# re: ruby 生成随机数 和 随机字符串
2010-11-06 11:00 |
One writes a persuasive thesis in formation to actualize a grandiose slice of academic education, such as in expectation to receive a master's degree. But there are people who provide custom dissertation, it’s better way.
回复 更多评论