Return a random separation of the string. Default separation is by charaacter.
"Ruby rules".at_rand(' ') #=> ["Ruby"]
# File lib/more/facets/random.rb, line 400
400: def at_rand( separator=// )
401: #separator = self.class.patterns( separator )
402: self.split(separator,1).at_rand
403: 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/more/facets/random.rb, line 412
412: def at_rand!( separator=// )
413: #separator = self.class.patterns( separator )
414: a = self.shatter( separator )
415: w = []; a.each_with_index { |s,i| i % 2 == 0 ? w << s : w.last << s }
416: i = Random.number(w.size)
417: r = w.delete_at( i )
418: self.replace( w.join('') )
419: return r
420: end
Return a random byte of self.
"Ruby rules".rand_byte #=> 121
# File lib/more/facets/random.rb, line 426
426: def rand_byte
427: self[Random.number(size)]
428: 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/more/facets/random.rb, line 436
436: def rand_byte!
437: i = Random.number(size)
438: rv = self[i,1]
439: self[i,1] = ''
440: rv
441: end
Return a random string index.
"Ruby rules".rand_index #=> 3
# File lib/more/facets/random.rb, line 447
447: def rand_index
448: Random.number(size)
449: end
Return the string with seperated sections arranged in a random order. The default seperation is by character.
"Ruby rules".shuffle #=> "e lybRsuur"
# File lib/more/facets/random.rb, line 456
456: def shuffle(separator=//)
457: split(separator).shuffle.join('')
458: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.