Resolves bugs: out of bounds

Resolves bugs: out of bounds if random length is bigger than the number of allowed chars