Improve String.random arguments check

Also changed implementation order to clarify dependencies