Formulas: RandomItem() and RandomSample()
Category: Lists (Arrays)
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?
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:
List
RandomItem(List, UpdateContinuously)
This is the list, table, or column that you want to search.
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
List
RandomSample(List, Count, WithReplacement, UpdateConinuously)
This is the list, table, or column that you want to search.
Count
RandomSample(List, Count, WithReplacement, UpdateContinuously)
This is the number of items you want this formula to produce.
Optional
WithReplacement
RandomSample(List, Count, WithReplacement, UpdateContinuously)
True/False; defaults to false. If true, items can appear multiple times.
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
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
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 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: I only want a person to show up once:
Your random sampling of customers
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 .