GROOVY-5925 Casting map as Random results in java.lang.VerifyError (mino...

Minor refactoring: moved the register length computation to a separate method.