sumpygump / rumble-text
生成随机文本。字符串、数字、单词、短语、句子等。可用于占位文本。
Requires (Dev)
README
Rumbletext 是一个简单的 PHP 库,用于生成随机文本。
我的意图是创建一个适合生成占位(lorem ipsum)文本的库。它使用原始算法来生成可发音的单词。它附带一些不同的字母集,用于在元音和辅音分布的概率中使用,以辅助这一功能。
安装
要安装,使用 composer 并执行以下命令
composer require sumpygump/rumble-text
用法
作为库
此库的主要用法是将它作为一个 PHP 项目的服务。实例化 RumbleText
类的一个实例,并调用各种函数,如 generateRandomWord()
。这将返回一个随机生成的单词。
示例
<?php
require_once 'vendor/autoload.php';
use RumbleText\RumbleText;
$rumble = new RumbleText(RumbleText::LETTERSET_ORIGINAL);
$word = $rumble->generateRandomWord();
echo $word . "\n";
可用方法列表
- generateRandomString($length, $chars)
- generateRandomPhrase($min = 1, $max = 5, $as_array = false)
- generateRandomSentence($min = 1, $max = 20, $as_array = false)
- generateRandomParagraph($min = 1, $max = 20, $exact_wordcount = null, $as_array = false)
- generateRandomArticle($min = 1, $max = 8, $exact_wordcount = null)
- generateRandomWord($length = 5, $lower_case = true, $ucfirst = false, $upper_case = false, $exactlength = false)
- generateRandomName($maxlength = 10)
- generateRandomCompany($maxwords = 2)
- generateRandomWebsite()
- generateRandomEmail()
- generateRandomDigits($minlength = 4, $maxlength = 16, $exactlength = 0)
- generateRandomPhone()
- generateRandomAddress()
作为 CLI 脚本
还有一个 CLI 脚本,可以从命令行输出各种随机字符串。
使用 rumble-text --help
获取以下帮助信息
Rumble-text generates random text.
Usage: rumble-text [--letterset <letterset>] [--type <type>] [--chars <chars>] [wordcount|length]
--letterset allows to select algorithm for probabilities of vowels and
consonants to use
--type allows to pick what type of entity to produce (whether string, word,
name, paragraph, etc.)
--chars is only used for type 'string', the format is a string of chars to
pick from. e.g. --chars abcdef012
some types use wordcount to output a certain number of words, and some types
use length to specify character length
Valid lettersets:
- original
- equal
- baba
- caesar
- hayden
- parseltongue
Valid types:
- string
- phrase
- sentence
- paragraph
- article
- word
- name
- company
- website
- email
- digits
- phone
- address
字母集
以下是可用的字母集展示。注意:字母集不用于 generateRandomString
或 generateRandomDigits
方法。
原始
原始字母集具有元音和辅音的简单分布。我手动进行了微调,使其看起来更美观。
Cojo pamfyresi petyop irwydaw, buspe pib hyto my satwotar! Tesasraf etydna
ahlesfome syvitvada mainvirrus er wor savmy paszote enmys cezaat cerrace
sa. Ohsepa sarba sit otsel vijizupe esnevremiro nidsol dovsi acis sedoltuz
yz tekecna hekeco pap hovabator. Botsibe osbapal vejeen syceirme tobhyt
astymak jefmesa soesmar dacov sonfif idsuznewe emsoc peb peumedav renodan.
Cim, ysgul. Enarutro eg abjis tabetatet tynyjjas nawhe et bemonot ergahe,
do?.
凯撒
凯撒字母集基于 caesar
手册页中描述的英语单词字母分布。
英语字母的频率(从最常用到最少用)如下:ETAONRISHDLFCMUGPYWBVKXJQZ。它们的百分比频率如下:E(13),T(10.5),A(8.1),O(7.9),N(7.1),R(6.8),I(6.3),S(6.1),H(5.2),D(3.8),L(3.4),F(2.9),C(2.7),M(2.5),U(2.4),G(2),P(1.9),Y(1.9),W(1.5),B(1.4),V(0.9),K(0.4),X(0.15),J(0.13),Q(0.11),Z(0.07)。
此字母集生成的文本如下
"Ter?" Awaf wile! Nelen ninfena turoab peti diced om pafatite opleh,
lagcomuni mepetometa tofegod. Et itad tis onurrateh ittejad he ananmeron
coesenni. Sarororih ostonet lyntav it oprir rela dekyro feid boerhe lansan
pewym sedisibe hosi runreh dolarmer itcihheg idunab. Noctona otruhe
nuenteci darerut nis dohsu meorensin lostonpes as socuis mofotlec nebon
dotag mense noy ef sito gifdeosel tan id. Teveta votiad ubsesmog gehmi
gomef? Gel eshes rerarog ew pocivis lomtadsece tonasofi arho. Temehe
wesanouf etder egopet. Kace fera oqon astesi sonefeh he atcuawhon eh tele
rose hofad tosoyat neamos famu selepa odit tatrid tetemlos dorodot. Ris ta
ren efareltis bessihes.
Hayden
在我寻找更好的近似人类单词的过程中,我发现了一篇由 Rebecca Hayden 编写的论文,其中她描述了各种音素及其在口语中的分布。我使用了她的论文结果来生成 hayden 字母集。
以下是 hayden 的示例
Ralawa it rofnayidiy rasnal nis thati ri taszalon ethfymu. Harzanne. Imzin
nadatura nisgenbomi favatazare pezetot iltatpas tiis hakimele amlasias
lyfus neinus tiziam derech yachi sat attathis afkaizev kihir thayefeth.
Reslika niglad tirostasu sital raregshuna tuzaalfar zari sir dalneal pidfiz
shatteti re, imnonara kir inmajapdi kat iswamekzi?
Danekitava lewit thachar. Ta natiwh vinan nay littera toim. Ang taatarla
mulalanik tialcheth isyah turthazah atnat valka apre sifthas yrvil yoyain?
Kashin nakef panni arif kav, rit ihavny lulkan al totu jayg fililin thyna ihta
imaj natna jeargi? Zaimnap na whemusha kur er ngata, vewfe anam. Azhthat arjeh
ilnaiwh hanema anasenry azilyng.
Equal
equal 字母集为每个字母选择具有相同概率。与前面的例子不同,没有对某些字母进行加权,因此最终会得到更多 j、z、x、w 和其他罕见字母。
Tadon owdocon picevo pumozupdiz rova ev rotpis tavaqag man ihpiminu
kemliwal? Oknit tofbihrela atifuy liokqat nojjoj. Subi ilmof diig yeuc
sayibuet tafiq xisayu xoja ek ozir juiy yelpeza boleso higohabe yoduzif.
Oloxroki coeskovo uszeaf got birfus cerpe seuj quaqufpu ejqemcup jaskel
nufo ipmuet xeaw ezde. Ji yutzilewa onjizueg gemikfoh atmahih. Webe bavi
unur qivo embamo fucixu dawa monus lip ifziquhka, wasov cogiew ucnoorced
yiol kiclaz ewjag sol? Kopefit viyojecoy tipiollir kez jezih. Omqaru ulgiru
ful lu jow jak wowquga faqweiwdab, enve cucfapi nuga binevuj qahkixi pez
tec sim? Gokeg xuowjinzez vuscujah qayaiy. Jeej huranilib cakufas mofcato
niondupis wohu sobkimo acfufhofu.
Baba
“baba”字母集只是为了好玩。它将随机选择一个元音和一个辅音,并且只使用这些字母生成单词。
示例输出。在这个例子中,它选择了 'x' 和 'i'
Xixxixxix ixxi xixix xixxixix ixxixi xix.
Ixxixix xixixi ixixxixix ix xixixxixi xixixixxix ixxixxix ixxixxiix
xiixxixi xixixixxi xixixixi xixix ix xix ixxiixix xixixxix xix xixiixxi
xixxi xixxixi. Ixxixix "xiixix?" Xi ixxixxi. Xixix xixxixxixi xix
ixxixxixix ix ixixxixi xiix ix ixxiixxix ixixxixi xixxixi xixxixi xixxi
xixix xiix xi. Ixixxixix xixxix xixixix xiixixxix xixixixi xixxixxi
xixixiix xixix xixxix xixiix xixixi xixi xixxixiix xixiix ixxiixix. Xixixix
xix xi ix ix xixi ixixxixi ixxixxixix xixixxix xixixi ixxixxix xixiix
xixxixiix ixxi? "Xixixxix?" Ixixxix xixxixix xixix xixixxi, xix xix xix. Xi
xixxi ixxix. Ix "xixi xixxi," xixix xixiix. Xix xixiixxix xix xixix,
xixiixxixi xixixix ix ix.
Parseltongue
Parseltongue 是另一个只是为了好玩而创建的字母集。这个字母集模拟了《哈利·波特》中的蛇语。
Sasufasa hisuhih hashi afhasas ahahsi tihas hihisesu essiha ushef hitisahih
ihfihih sufa hah sishit sifihhu fuuffih si ihes sehu sas. Ahfahisi tihhahi
eshatih hifi saha, assahasi hahisah fihhehsa fiihsih. Hut ifsiih fah
hissusasi siha as hesah ifihfih uhahsihi sah sisasahus ahhas safa hasi
asahsahu. Saih hifashiha isih itsa fusihis hahaat ashis hehsisi isit sas si
huh hahtuh tasah afhah ih hahfa sihasuse. Sisi sisahis? Hasha hefisatsi
ifef hah hahis sah saha sahahusas hahi hihisa hih hahseseas ihhihasah
"sassias hassitsasi," sasisfes hasi. Sisias hatehhih sausahsah sis hahfisih
hahsah tisih sifisihfihi ashehti hesihha sasisuha fissuf sifasa hisahhah
ahhuhfit sahahe. Ihsis tihasse sashiih.