Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »
Try it now »
(no sign-in required)

Make Up a Random Name

Create random pronounceable nicknames for yourself and your friends.

Run the code to make a random sequence of 6 letters. Try it several times; try lengths other than 6:

SHOW/HIDE DETAILS

This gives the list of characters from a to z:

In[1]:=1
CharacterRange["a", "z"]
Out[1]=1

RandomChoice chooses a random character from the list. Each time you run the code, you get a different choice:

In[2]:=2
RandomChoice[CharacterRange["a", "z"]]
Out[2]=2

This gives a list of 6 random characters:

In[3]:=3
RandomChoice[CharacterRange["a", "z"], 6]
Out[3]=3

HIDE DETAILS
In[1]:=1
RandomChoice[CharacterRange["a", "z"], 6]
Out[1]=1

Get lists of vowels and consonants. Try adding y to the list of vowels:

SHOW/HIDE DETAILS

Make a list of the vowels and give it the name vowels:

In[1]:=1
vowels = {"a", "e", "i", "o", "u"}
Out[1]=1

Using the name vowels is the same as using the list:

In[2]:=2
vowels
Out[2]=2

Complement gives all of the elements of the first list that are not in the second list. For example:

In[3]:=3
Complement[{1, 2, 3, 4, 5}, {2, 4}]
Out[3]=3

The consonants are the letters that are not vowels:

In[4]:=4
consonants = Complement[CharacterRange["a", "z"], vowels]
Out[4]=4

HIDE DETAILS
In[1]:=1
vowels = {"a", "e", "i", "o", "u"}; consonants = Complement[CharacterRange["a", "z"], vowels]
Out[1]=1

Make random words out of 4 letters. Try other patterns of consonants and vowels:

Note: be sure you have already run the previous step.

SHOW/HIDE DETAILS

This gives a random consonant:

In[1]:=1
RandomChoice[consonants]
Out[1]=1

This gives a random vowel:

In[2]:=2
RandomChoice[vowels]
Out[2]=2

String together consonants and vowels in a list to make random words:

In[3]:=3
{RandomChoice[consonants], RandomChoice[vowels], RandomChoice[consonants], RandomChoice[vowels]}
Out[3]=3

HIDE DETAILS
In[1]:=1
{RandomChoice[consonants], RandomChoice[vowels], RandomChoice[consonants], RandomChoice[vowels]}
Out[1]=1

Make a list of 4 alternations of consonants and vowels. Try numbers other than 4:

SHOW/HIDE DETAILS

Table makes lists of things.

This makes a list of 4 random consonants:

In[1]:=1
Table[RandomChoice[consonants], {4}]
Out[1]=1

This makes a list of 4 consonant-vowel lists:

In[2]:=2
Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]
Out[2]=2

Flatten flattens out the sublists:

In[3]:=3
Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]
Out[3]=3

HIDE DETAILS
In[1]:=1
Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]
Out[1]=1

Display the letters as a word in 40-point type. Try changing the size to something other than 40for example, 80:

SHOW/HIDE DETAILS

StringJoin joins text strings in a list into a single text string:

In[1]:=1
StringJoin[{"wolf", "ram"}]
Out[1]=1

Use it to make a word out of a list of random letters:

In[2]:=2
StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]]
Out[2]=2

Change the size of text with Style. This writes wolfram in 40-point text (a point is a printers measure equal to 1/72 inch):

In[3]:=3
Style["wolfram", 40]
Out[3]=3

Write a random word in 40-point text:

In[4]:=4
Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40]
Out[4]=4

HIDE DETAILS
In[1]:=1
Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40]
Out[1]=1

Make a column of 6 random names. Try numbers of names other than 6:

SHOW/HIDE DETAILS

Column formats lists of things as columns:

In[1]:=1
Column[{"one", "two", "three", "four"}]
Out[1]=1

Make a list of 6 random names:

In[2]:=2
Table[Style[ StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40], {6}]
Out[2]=2

Use Column to format the names in a column:

In[3]:=3
Column[Table[ Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40], {6}]]
Out[3]=3

HIDE DETAILS
In[1]:=1
Column[Table[ Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40], {6}]]
Out[1]=1

Share Itmake a website that gives you a different random name each time you visit it:

SHOW/HIDE DETAILS

Deploy the random name code to the Wolfram Cloud, where anyone can use it:

In[1]:=1
CloudDeploy[ Delayed[ExportForm[ vowels = {"a", "e", "i", "o", "u"}; consonants = Complement[CharacterRange["a", "z"], vowels]; Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40], "PNG"]], "Permissions" -> "Public" ]
Out[1]=1

Click the link in the output to visit the site. Refresh the page in your browser to get a new random name.

Tell the world about your creation by sharing the link via email, tweet or other message.

HIDE DETAILS
In[1]:=1
CloudDeploy[ Delayed[ExportForm[ vowels = {"a", "e", "i", "o", "u"}; consonants = Complement[CharacterRange["a", "z"], vowels]; Style[StringJoin[ Flatten[Table[{RandomChoice[consonants], RandomChoice[vowels]}, {4}]]], 40], "PNG"]], "Permissions" -> "Public" ]
Out[1]=1