replacing rand calls with Array#sample

The only code that is 1.9.3-specific is test code. I converted it to support 1.9.2.