Function Repository Resource:

RandomText

Source Notebook

Generate a random piece of text

Contributed by: Sushma Kini

ResourceFunction["RandomText"][n]

gives text containing n random words.

ResourceFunction["RandomText"][n,type]

gives text containing n instances of textual unit type, consisting of random words.

ResourceFunction["RandomText"][]

gives text containing 100 random words.

Details and Options

ResourceFunction["RandomText"][n] is the same as ResourceFunction["RandomText"][n,"Word"].
ResourceFunction["RandomText"][] is the same as ResourceFunction["RandomText"][100].
Possible settings for type include:
"Word"gives n words
"Sentence"gives n sentences
"Paragraph"gives n paragraphs
ResourceFunction["RandomText"] takes a Language option, which defaults to $Language.

Examples

Basic Examples (3) 

Generate text containing 15 random words:

In[1]:=
ResourceFunction["RandomText"][15]
Out[1]=

Text containing 100 random words:

In[2]:=
ResourceFunction["RandomText"][]
Out[2]=

Generate text containing two sentences of random words:

In[3]:=
ResourceFunction["RandomText"][2, "Sentence"]
Out[3]=

Scope (2) 

RandomText formats words into sentences and paragraphs if these types are specified:

In[4]:=
ResourceFunction["RandomText"][2, "Paragraph"]
Out[4]=

RandomText[n,"Word"] gives unformatted words:

In[5]:=
ResourceFunction["RandomText"][200, "Word"]
Out[5]=

Options (2) 

Language (2) 

Generate random German text:

In[6]:=
ResourceFunction["RandomText"][20, Language -> "German"]
Out[6]=

Language specification can also be "Language" entities:

In[7]:=
ResourceFunction["RandomText"][20, Language -> Entity["Language", "Hindi"]]
Out[7]=

Possible Issues (3) 

If the type specified is not a supported type, a Failure is returned:

In[8]:=
ResourceFunction["RandomText"][20, "Page"]
Out[8]=

If there are no words available for a particular language, a Failure is returned:

In[9]:=
ResourceFunction["RandomText"][20, "Paragraph", Language -> "Chinese"]
Out[9]=

Sentences most likely won’t have proper grammar:

In[10]:=
ResourceFunction["RandomText"][1, "Sentence"]
Out[10]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 13 February 2019

License Information