Rewrite of word generation function around random-lib.

Additional test coverage.