code: private int generateScratchCode()
      {
          while (true)
          {
              byte[] scratchCodeBuffer = new byte[BYTES_PER_SCRATCH_CODE];
              secureRandom.nextBytes(scratchCodeBuffer);
  
              int scratchCode = calculateScratchCode(scratchCodeBuffer);
  
              if (scratchCode != SCRATCH_CODE_INVALID)
              {
                  return scratchCode;
              }
          }
      }
docs: This method creates a new random byte buffer from which a new scratch
  code is generated. This function is invoked if a scratch code generated
  from the main buffer is invalid because it does not satisfy the scratch
  code restrictions.
  
  @return A valid scratch code.