How to pick a random english word from a list [clo

2019-01-17 23:34发布

What would be the best way to go about getting a function that returns a random English word (preferably a noun), without keeping a list of all possible words in a file before hand?

标签: python random
8条回答
在下西门庆
2楼-- · 2019-01-18 00:24

You can't. There is no algorithm to generate meaningful words. You can only generate words that sound like English, but they won't have any meaning.

查看更多
Fickle 薄情
3楼-- · 2019-01-18 00:29

There's a random word generator here - it's not English but it's English-ish, i.e. the words are similar enough to language that a user can read the words and store them in short-term memory.

Source code is in C# and a bit kludged, but you could use a similar approach in Python to generate lots of words without having to store a massive list.

Alternatively, you could call the web service on the demo page directly - it's hosted on GoDaddy though, so no guarantees it will work in production!

查看更多
登录 后发表回答