improve randomBytes to deal with the buffer