securerandom という単語を忘れがちなので
1
2
3
4
|
irb(main):004:0> rand
=> 0.09952308363901874
irb(main):005:0> rand
=> 0.8386071792414577
|
1
2
3
4
5
6
|
irb(main):032:0> rand(3)
=> 1
irb(main):033:0> rand(3)
=> 0
irb(main):034:0> rand(3)
=> 2
|
1
2
3
4
5
6
|
irb(main):193:0> rand(98..100)
=> 98
irb(main):194:0> rand(98..100)
=> 100
irb(main):195:0> rand(98..100)
=> 99
|
1
2
3
4
|
irb(main):001:0> require 'securerandom'
=> true
irb(main):002:0> SecureRandom.uuid
=> "94c1ced9-4f9b-43b3-b78e-8afa863247b3"
|
1
2
3
4
|
irb(main):001:0> require 'securerandom'
=> true
irb(main):002:0> SecureRandom.hex
=> "2cf9e261fbdbb58759a43630b75bbbb6"
|
1
2
|
irb(main):013:0> 8.times.map { ((0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a).sample }.join
=> "GgDrgd3b"
|
1
2
3
4
|
irb(main):221:0> SecureRandom.hex(4)
=> "c6f25461"
irb(main):013:0> 8.times.map { rand(16).to_s(16) }.join # これでもいい
=> "8171f7a6"
|
1
2
|
irb(main):216:0> 8.times.map { (32..126).map(&:chr).sample }.join
=> "{Ykw?5SU"
|
1
2
|
irb(main):094:0> 8.times.map { %w(a b c d e f g h i j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z # $ % & !).sample }.join
=> "bMeqD$Ta"
|
こういうのは後で見たときにわかりやすいのが一番です!
とワシは思います
コメント