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)

Pick a Word Beginning with X

Find a random word in the dictionary that starts with a particular letter.

Run the code to get a list of all the words in the dictionary:

DictionaryLookup[]

Show words beginning with “x”. Try a different starting letter:

SHOW/HIDE DETAILS

The pattern “x”~~___ matches an “x” followed by one or more letters:

DictionaryLookup["x" ~~ ___]

You can combine letters and blanks to find words matching all sorts of patterns. Here are words that start and end with “x”:

DictionaryLookup["x" ~~ ___ ~~ "x"]

HIDE DETAILS
DictionaryLookup["x" ~~ ___]

Make a random choice among words beginning with “x”. Try a different starting letter:

SHOW/HIDE DETAILS

RandomChoice chooses an element at random from a list. Re-run the code to get a different choice:

RandomChoice[{1, 2, 3, 4, 5}]

Choose a word at random that starts with “x”:

RandomChoice[DictionaryLookup["x" ~~ ___]]

HIDE DETAILS
RandomChoice[DictionaryLookup["x" ~~ ___]]

Choose 5 random words beginning with “x”. Try other numbers:

SHOW/HIDE DETAILS

Specify the number of words to get more than one:

RandomChoice[DictionaryLookup["x" ~~ ___], 5]

Use RandomSample to get random words that don’t repeat:

RandomSample[DictionaryLookup["x" ~~ ___], 5]

HIDE DETAILS
RandomSample[DictionaryLookup["x" ~~ ___], 5]