Fix a bug with function _random_str()

Ensure function does not generate illegal UTF-8 characters.
Add tests for form CharacterForm