Wolfram Research

RandomText

Contributed by: Sushma Kini

Source Notebook

Generate a random piece of text

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

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 2 sentences of random words:

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

Scope

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

Language

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

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 won’t necessarily have proper grammar:

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

Resource History