Gallery
RandomItem & RandomSample
Share
Explore

icon picker
RandomItem & RandomSample

Formulas: RandomItem() and RandomSample()
Category: Lists (Arrays)
variation.svg
RandomItem()
This formula outputs a single random item from a list
or stated otherwise...
Hey Coda, can you take a look at this list, randomly choose an item, and give it to me?

random.svg
RandomSample()
Outputs a user-determined number of items from a list
put a bit simpler...
Hey Coda, can you take a look at this list, pick a provided number of variables, and give them to me?
RandomItem() takes two parameters:
ingredients-list (1).svg
List

RandomItem(List, UpdateContinuously)

This is the list, table, or column that you want to search.
approve-and-update.svg
UpdateContinuously

RandomItem(List, UpdateContinuously)

Defaults to true. If true, it will update the item whenever doc is edited.

RandomSample() takes four parameters. Two are required and two are optional.
Required
ingredients-list (2).svg
List

RandomSample(List, Count, WithReplacement, UpdateConinuously)

This is the list, table, or column that you want to search.
abacus (2).svg
Count

RandomSample(List, Count, WithReplacement, UpdateContinuously)

This is the number of items you want this formula to produce.
Optional
replace (1).svg
WithReplacement

RandomSample(List, Count, WithReplacement, UpdateContinuously)

True/False; defaults to false. If true, items can appear multiple times.

approve-and-update (1).svg
UpdateContinuously

RandomSample(List, Count, WithReplacement, UpdateContinuously)

Defaults to true. If true, it will update the item whenever doc is edited.

RandomItem()

Here's a little list of plants.
Blessed Milk ThistleItalian ThistleLady FernThimbleberryWolf’s milk slimeBritish Columbia Wild GingerBeaked Hazelnut
Try pressing the buttons below as many times as you like and watch how they both choose a random plant from our plants list, but also notice how their behavior differs
Random Plant: True as 2nd parameter
Random Plant: False as 2nd parameter
British Columbia Wild Ginger
Explanation of true parameter
When RandomItem() has its 2nd parameter set to True() it will choose a new random item from its target list every time, even if that item is randomly the same as the selection before

Explanation of false parameter
When RandomItem() has its 2nd parameter set to False() it will choose a random item the very first time it is called and then it will continue to return that random item every time

A little game - Magic 8 ball the Coda way

Sorry to break it to you, but Magic 8 balls are not actually Magic. They are simply a RandomItem() Coda formula in the form of a black ball. When you shake the Magic 8 ball a many-sided die brings up a random saying to answer your question.
Try out this Coda version of a Magic 8 ball that relies on RandomItem() to pull a Random item from the table as an answer to your question
figma 1 (17).png
Reset and ask again
✨ Outlook not so good ✨
figma 1 (17).png
Question
1
8
There are no rows in this table

RandomSample()

RandomSample() is a bit different than RandomItem() in that its primary purpose is to draw out sample sets of data from a larger set. For example...
You run a business that sells running-shoes, and the 500 people in the
Broken link
table are some of your customers. You are hoping to get some feedback about a new shoe design you recently launched but obviously don’t want your team calling each and every one of your customers.
This is where RandomSample() comes in. Use the controls below to create your sample set
I want a sample size of:
00
1
I only want a person to show up once:

Your random sampling of customers
@Ronnie Gross
Now that you have a random-set of customers, you can go ahead and send them that request for feedback! If you want to stick with Coda, the is a fantastic resources and can automatically email each individual from your sample set combined with the use of
Broken link
.

Done
Done
Create large sets of mock data using RandomItem and RandomSample()
Done


Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.