随笔-167  评论-65  文章-0  trackbacks-0

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



write by feng
posted on 2009-03-27 19:13 fl1429 阅读(8272) 评论(5)  编辑  收藏

评论:
# re: ruby 生成随机数 和 随机字符串 2010-01-02 04:32 | poCHLOE
Very often different persons make the efforts to search for just some idea about <a href="http://bestwritingservice.com/buy-essay1.html">buy essay</a>. And I would offer to utilize the help of <a href="http://www.bestwritingservice.com">writing services</a>. At the same time, this is real to use some stuff from the this topic topic.   回复  更多评论
  
# re: ruby 生成随机数 和 随机字符串 2010-03-31 10:58 | article submit
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 | dissertation
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 | dissertation
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.  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
已访问数:
free counters