% irb18 -KU irb(main):001:0> require 'securerandom' => true irb(main):003:0> SecureRandom.random_bytes(32).split("").size => 22 Without UTF-8 strings, or with Ruby 1.9, the problem is not there and it always returns 32. This actually causes uuidtools to break.
This is not yet fixed in ruby 1.8.7_p173
Looking at this again I wonder if this isn't a bug in uuidtools: perhaps it should check for the $KCODE stuff and change its code accordingly. After all you've requested all string to be UTF-8 with the -K option. In any case 1.8.7_p302 and ree18 1.8.7.2010.02-r1 both still have this behaviour. jruby runs out of heap space.
Thinking about this a bit more it seems to be that this is by design due to ruby 1.8's lack of proper support for UTF-8.