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 閱讀(8288)
評論(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.
回復 更多評論