Random Nutrient Picker

Select nutrient record IDs from a caller-supplied normalized dataset while preserving dataset and source provenance.

Description

Select nutrient record IDs from your candidate list while returning its dataset and source labels.

A nutrient dataset can assign stable IDs to nutrient definitions, with names, units, and classification stored in separate records. Selecting a definition ID is distinct from generating a food composition measurement or an intake recommendation.

Provenance can record origins and context of data.1

Here datasetId, datasetVersion, and sourceId are caller-supplied labels copied into the result, not verified lineage or a complete provenance record.

Provide the nutrient catalog and unique candidate IDs yourself. The returned selectedIds are references, not complete records; the tool performs no external lookup. Sampling defaults to without replacement within one run.

When to use Random Nutrient Picker

Use it for nutrient-definition flashcards or nutrition-data fixtures when an explicit source dataset and eligible candidate list are available.

How to use Random Nutrient Picker and understand its results

  1. Enter 1–1,000 unique nonblank candidateIds and nonblank datasetId, datasetVersion, and sourceId. Resolve the IDs against your own catalog.
  2. Enter selectionCount from 1 through 1,000. Leave withReplacement false to select distinct IDs, with count no greater than the candidate list; set it true to allow repeated draws.
  3. Run the picker and read selectedIds with the returned dataset and source labels. Retrieve record details from that same dataset version separately.
with replacement: index = floor(randomDraw × candidate count)

Each draw samples the complete candidate list, so the same ID can recur within a result.

Without replacement, the implementation copies the candidate list and performs a partial Fisher–Yates shuffle: on draw d, choose a position from d through the final index, swap it into position d, and emit that ID. With independent uniform draws, remaining candidates are equally likely; the input list is not mutated.

ID equality is exact string equality. Blankness is checked after trimming, but accepted IDs and metadata are returned as supplied rather than trimmed or normalized.

json
{
  "input": {
    "candidateIds": [
      "candidate-a",
      "candidate-b",
      "candidate-c"
    ],
    "datasetId": "example/nutrient",
    "datasetVersion": "1",
    "selectionCount": 2,
    "sourceId": "example",
    "withReplacement": false
  },
  "randomDraw": 0.25,
  "output": {
    "datasetId": "example/nutrient",
    "datasetVersion": "1",
    "selectedIds": [
      "candidate-a",
      "candidate-b"
    ],
    "sourceId": "example"
  }
}

One candidate can be drawn repeatedly when replacement is enabled. Without replacement, requesting more selections than candidates is rejected. Duplicate IDs, empty lists, blank labels, and invalid random draws also fail. Duplicates may recur across separate runs.

Limitations and assumptions

The default source is Math.random; no seed input or cryptographic entropy guarantee is provided. Repeated runs may select the same result, and the distribution depends on the random source.

It does not recommend intakes, evaluate diets, supply nutrient quantities, or include a built-in nutrient reference table.

The generator does not validate record existence, source authority, dataset version availability, category membership, or coverage. Equal selection probability over supplied IDs is not a representative sample of a market or population.

Alternative or Complementary methods

Prepare filters and normalized records before selection, then retrieve details after it. General catalog selectors use the same selection concept for a broader domain; a bounded integer generator can support a simple index exercise without preserving catalog labels.

References

  1. PROV-Overview: An Overview of the PROV Family of Documents — World Wide Web Consortium

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies