随机名称和段塞发生器
coolname的Python项目详细描述
你想要随机的人类可读字符串吗?
>>>fromcoolnameimportgenerate_slug>>>generate_slug()'big-maize-lori-of-renovation'>>>generate_slug()'tunneling-amaranth-rhino-of-holiness'>>>generate_slug()'soft-cuddly-shrew-of-expertise'
功能
生成鼻涕虫,即用,django兼容。
>>>fromcoolnameimportgenerate_slug>>>generate_slug()'qualified-agama-of-absolute-kindness'
将名称作为序列生成,并对其执行任何所需的操作。
>>>fromcoolnameimportgenerate>>>generate()['beneficial','bronze','bee','of','glee']>>>' '.join(generate())'limber transparent toad of luck'>>>''.join(x.capitalize()forxingenerate())'CalmRefreshingTerrierOfAttraction'
生成特定长度的名称:2、3或4个单词。
>>>generate_slug(2)'mottled-crab'>>>generate_slug(3)'fantastic-acoustic-whale'>>>generate_slug(4)'military-diamond-tuatara-of-endeavor'
Note: without argument, it returns a random length, but probability of 4‑word name is much higher.Prepositions and articles (of, from, the) are not counted as words.
超过10个随机名字。
Words Combinations Example 4 1010 ^{tt1}$ 3 108 ^{tt2}$ 2 105 ^{tt3}$ >>>fromcoolnameimportget_combinations_count>>>get_combinations_count(4)60610181372
精心挑选的词汇。sexy和demonic是这里最“无礼”的词- 但只有一小撮,为了调味品。大多数单词要么是中性的,比如red,要么是正的, 例如brave。主题总是一些动物,鸟,鱼或昆虫-你不能比 大自然之母。
Easy customization。创造你自己的规则!
>>>fromcoolnameimportRandomGenerator>>>generator=RandomGenerator({...'all':{...'type':'cartesian',...'lists':['first_name','last_name']...},...'first_name':{...'type':'words',...'words':['james','john']...},...'last_name':{...'type':'words',...'words':['smith','brown']...}...})>>>generator.generate_slug()'james-brown'
安装
pip install coolname
coolname是用纯python编写的,没有依赖项。它适用于任何现代python版本,包括pypy。
发布历史记录
1.1.0(2018-08-02)
- 支持32位python。
1.0.4(2018-02-17)
中断更改:
- Renamed ^{tt8}$ to ^{tt9}$.
- ^{tt10}$ was removed, because it was just an alias to ^{tt11}$.
Phrase lists 在创建自定义生成器时给您更多的自由。
您可以种子化甚至替换底层的random.Random实例,请参见 Randomization。
使用COOLNAME_DATA_DIR和COOLNAME_DATA_MODULE更改默认生成器。这也节省了内存!
组合总数=600亿。
有关早期版本,请参见History