Function Repository Resource:

RandomItem

Source Notebook

Create a random item of the specified type

Contributed by: Arnoud Buzing

ResourceFunction["RandomItem"][item]

generates a random item of the specified type.

ResourceFunction["RandomItem"][item,n]

generates n random items.

Details and Options

ResourceFunction["RandomItem"] can be used to generate data validation test cases.
Supported basic item types include:
"CreditCard"credit card number
"Emoji"emoji character
"PersonName"person's name
"Address"full address
"PhoneNumber"phone number
"StreetAddress"street address
"UserAgent"browser's user agent string
"BankAccount"basic bank account number (BBAN)
Specific bank account items are specified with {"BankAccount",type} where type is any of:
"ABA"bank routing number
"BBAN"basic bank account number
"IBAN"international bank account number
"SWIFT"international SWIFT code (8 or 11 digits)
"SWIFT11"11-digits SWIFT code
"SWIFT8"8-digit SWIFT code
Specific user agent items are specified with {"UserAgent",type} where type is any of:
"Chrome"Chrome browser
"Firefox"Firefox browser
"InternetExplorer"Internet Explorer browser
"Opera"Opera browser
"Safari"Safari browser
ResourceFunction["RandomItem"] calls functionality from the external "faker" package (Python).
Certain item types, but not all, support a "Locale" option for localized results. The default locale setting is "en-US".
Locales are typically specified in the "language-COUNTRY" format, for example: "fr-BE" or "nl-BE".
Certain locales can be specified by their language name, for example: "Portuguese" or "Japanese".

Examples

Basic Examples (3) 

Generate random name:

In[1]:=
ResourceFunction["RandomItem"][{"Person", "Name"}]
Out[1]=

Generate a street address:

In[2]:=
ResourceFunction["RandomItem"][{"Address", "StreetAddress"}]
Out[2]=

Generate random emojis:

In[3]:=
ResourceFunction["RandomItem"][{"Text", "Emoji"}, 4]
Out[3]=

Scope (15) 

Person names (3) 

Generate a Dutch name:

In[4]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, "Locale" -> "nl_NL"]
Out[4]=

Generate a French name:

In[5]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, "Locale" -> "French"]
Out[5]=

Generate four Japanese names:

In[6]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, 4, "Locale" -> "Japanese"] // Column
Out[6]=

Credit cards (2) 

A complete credit card specification:

In[7]:=
ResourceFunction["RandomItem"]["CreditCard"]
Out[7]=

Generate various random credit card properties:

In[8]:=
ResourceFunction["RandomItem"][{"CreditCard", "Number"}, 4]
Out[8]=
In[9]:=
ResourceFunction["RandomItem"][{"CreditCard", "ExpirationDate"}, 4]
Out[9]=
In[10]:=
ResourceFunction["RandomItem"][{"CreditCard", "Provider"}, 4]
Out[10]=

User agents (1) 

A few random user agents that identify web browsers:

In[11]:=
ResourceFunction["RandomItem"]["UserAgent", 3] // Column
Out[11]=
In[12]:=
ResourceFunction["RandomItem"][{"UserAgent", "Chrome"}, 3] // Column
Out[12]=
In[13]:=
Map[ResourceFunction["RandomItem"][{"UserAgent", #}] &, {"Safari", "Chrome", "Opera", "Firefox", "InternetExplorer"}] // Column
Out[13]=

Phone numbers (1) 

Generate phone numbers:

In[14]:=
ResourceFunction["RandomItem"][{"Person", "PhoneNumber"}, 4] // Column
Out[14]=

Bank accounts (6) 

Generate bank routing numbers (ABA):

In[15]:=
ResourceFunction["RandomItem"][{"BankAccount", "ABA"}, 4] // Column
Out[15]=

Generate basic bank account numbers (BBAN):

In[16]:=
ResourceFunction["RandomItem"][{"BankAccount", "BBAN"}, 4] // Column
Out[16]=

Generate international bank account numbers (IBAN):

In[17]:=
ResourceFunction["RandomItem"][{"BankAccount", "IBAN"}, 4] // Column
Out[17]=

Generate SWIFT codes:

In[18]:=
ResourceFunction["RandomItem"][{"BankAccount", "SWIFT"}, 4] // Column
Out[18]=

Generate 8-digit SWIFT codes:

In[19]:=
ResourceFunction["RandomItem"][{"BankAccount", "SWIFT8"}, 4] // Column
Out[19]=

Generate 11-digit SWIFT codes:

In[20]:=
ResourceFunction["RandomItem"][{"BankAccount", "SWIFT11"}, 4] // Column
Out[20]=

Barcodes (2) 

Generate 8-digit EAN barcodes:

In[21]:=
ResourceFunction["RandomItem"][{"Barcode", "EAN8"}, 4] // Column
Out[21]=

Generate 13-digit EAN barcodes:

In[22]:=
ResourceFunction["RandomItem"][{"Barcode", "EAN13"}, 4] // Column
Out[22]=

Options (4) 

Certain item types support a "Locale" option for localized results that can be given in various ways:

In[23]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, 4, "Locale" -> "nl_NL"] // Column
Out[23]=

Generate a French name:

In[24]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, 4, "Locale" -> "French"] // Column
Out[24]=

Generate Japanese names:

In[25]:=
ResourceFunction["RandomItem"][{"Person", "Name"}, 4, "Locale" -> "ja-JP"] // Column
Out[25]=

Generate German addresses:

In[26]:=
ResourceFunction["RandomItem"]["Address", 4, "Locale" -> "de_DE"] // Column[#, Frame -> All] &
Out[26]=

Applications (2) 

Generate synthetic user data that can be used for testing web forms:

In[27]:=
Dataset[Table[ResourceFunction["RandomItem"]["Person"], 10]]
Out[27]=
In[28]:=
Dataset[Table[
  AssociationMap[ResourceFunction[
   "RandomItem"], {{"Person", "Name"}, {"Address", "StreetAddress"}, "BankAccount"}], 10]]
Out[28]=

Generate a Greek dataset with validation data:

In[29]:=
Dataset[Table[
  AssociationMap[
   ResourceFunction["RandomItem"][#, "Locale" -> "greek"] &, {"PersonName", "StreetAddress", "BankAccount"}], 10]]
Out[29]=

Publisher

WolframExternalFunctions

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.1 – 03 June 2024
  • 1.0.0 – 22 May 2024

Related Resources

License Information