Return a random separation of the string. Default separation is by charaacter.
"Ruby rules".at_rand(' ') #~> ["Ruby"]
# File lib/facets/random.rb, line 369 def at_rand( separator=// ) #separator = self.class.patterns( separator ) self.split(separator,-1).at_rand end
Return a random separation while removing it from the string. Default separation is by character.
s = "Ruby rules" s.at_rand!(' ') #~> "Ruby" s #~> "rules"
# File lib/facets/random.rb, line 381 def at_rand!( separator=// ) #separator = self.class.patterns( separator ) a = self.shatter( separator ) w = []; a.each_with_index { |s,i| i % 2 == 0 ? w << s : w.last << s } i = Random.number(w.size) r = w.delete_at( i ) self.replace( w.join('') ) return r end
Return a random byte of self.
"Ruby rules".rand_byte #~> 121
# File lib/facets/random.rb, line 395 def rand_byte self[Random.number(size)] end
Destructive rand_byte. Delete a random byte of self and return it.
s = "Ruby rules" s.rand_byte! #~> 121 s #~> "Rub rules"
# File lib/facets/random.rb, line 405 def rand_byte! i = Random.number(size) rv = self[i,1] self[i,1] = '' rv end
Return a random string index.
"Ruby rules".rand_index #~> 3
# File lib/facets/random.rb, line 416 def rand_index Random.number(size) end
Generated with the Darkfish Rdoc Generator 2.