超的博客
文章 标签 我
搜索结果

ruby随机生成字符串

2018-08-12

shuffle

(("0".."9").to_a + ("A".."Z").to_a).shuffle[0..6].to_a.join

shuffle: 随机排列,中文名称是洗牌

sample

(("0".."9").to_a +  ("A".."Z").to_a).sample(6).join

*

[*'0'..'9',*'A'..'Z'].sample(6).join

*的意思是将范围展开

  • ruby
<  rails-自关联
rails_console好用的技巧 >
© 2025 dc
Powered by Hugo with theme Minos