Generating random list from dataset

This must be explained somewhere, but I can’t find it. I’ve uploaded a Dataset, and now I want to use that Dataset to randomly populate a list. I was trying to use the Custom List selector, and then in the function use from_dataset, but that doesn’t seem to be what I need. I then tried the Dataset Column selector, but that only returns 1 randomly from the Dataset. How do I go about generating a random list from a Dataset?

It sounds like you are using the Dataset Column type correctly. What is your schema set to when you generate your records? There is at the bottom of the schema # Rows

If you’re outputting json and want an array of values randomly chose from your dataset, you can add the cardinality in brackets to the field name:

For example, to generate something like

{
  "colors": ["red", "green", "blue"]
}

Use “colors[3]” as your field name. You can also specify a range like “colors[2-4]” to generate between 2 and 4 values, inclusive.

1 Like

This does sound like what I want, but I’m not following here. The disconnect for me is that I don’t know which Type I should be using, and then how do I access the Dataset within that Type? Would it be in a formula?

Use the Dataset Column type.

1 Like

Oh, I think I understand what you’re saying. I would use a Dataset Column as the Type, and then in the field, I would reference the array like here. That’s really awesome. Thank you!

Now taking it just one step further… is it possible to return the Dataset object, instead of a single property? So in my example above, I’m returning AffiliationName, but I’d like to return an array of Affiliation objects… so the items would include both the AffiliationName and AffiliationId.

Yes, here’s an example: https://mockaroo.com/c0ce9000

You use the JSON Array datatype and then put the object fields underneath it and name them starting with the name of the array and a “.”. In this case I’m using the built in types First Name and Last Name, but you would use Dataset Columns for those.

Duh. Thank you all for the help!