In: |
rand.rb
|
Parent: | Object |
Return a random byte of self.
"Ruby rules".pick_byte #=> 121
# File rand.rb, line 185 185: def pick_byte 186: self[pick_index] 187: end
Return a single-character string of a random character in self.
"Ruby rules".pick_char #=> "y"
# File rand.rb, line 191 191: def pick_char 192: pick_byte.chr 193: end
Return a random byte index of self.
"Ruby rules".pick_index #=> 3
# File rand.rb, line 217 217: def pick_index 218: rand(size) 219: end
Destructive pick_index. Delete a random byte of self and return it’s index.
s = "Ruby rules" s.pick_index #=> 3 s #=> "Rub rules"
# File rand.rb, line 226 226: def pick_index! 227: i = pick_index 228: self[i,1] = "" 229: i 230: end
Return the string with characters arranged in random order.
"Ruby rules".shuffle_chars #=> "e lybRsuur"
# File rand.rb, line 170 170: def shuffle_chars 171: split(//).shuffle.join('') 172: end
Destructive shuffle_chars. Arrange the characters of the string in new, random order.
s = "Ruby rules".shuffle_chars s.shuffle_chars! s #=> "e lybRsuur"
# File rand.rb, line 179 179: def shuffle_chars! 180: self[0,size] = shuffle_chars 181: end