Skip to content

Main content

Random Food by Nutrient Picker

Choose foods from USDA records, set a nutrient range per 100 g, and pick from the matching candidates.

Loading tool…

Description

Filter supplied normalized food-composition records by an inclusive per-100-gram nutrient range in one explicit unit, then reuse the food catalog selector and return full selected records with provenance; missing nutrients are unknown, not zero, and no dietary recommendation is implied.

Nutrient amounts per 100 g compare foods on a common mass basis. Selecting a food within a numeric nutrient range is different from choosing a serving size, evaluating a diet, or checking individual medical and allergy needs.

Filter supplied normalized food-composition records by an inclusive per-100-gram nutrient range in one explicit unit, then reuse the food catalog selector and return full selected records with provenance; missing nutrients are unknown, not zero, and no dietary recommendation is implied.

When to use this tool

Use this generator to create reproducible food by nutrient cases from the supplied model or bank. Inspect the returned evidence before using cases in a test or exercise.

How to use the tool and how it works

  1. Supply foods, nutrientId, unit, minimumPer100g, maximumPer100g, datasetId, datasetVersion, sourceId, selectionCount, withReplacement in the field shapes below. Set seed when you need an explicit replay.
  2. Run the tool and correct any input error. For generated controls, distinguish a successful fixture containing an invalid case from failure to generate the fixture.
  3. Read selectedFoods, eligibleCount, datasetId, datasetVersion, sourceId. Use the conventions below. Keep answer-bearing fields separate when presenting an exercise.

Validate supplied food IDs and source metadata, find the requested nutrient with exactly matching units, and filter inclusively by amount per 100 g. Delegate sampling from eligible food IDs under the replacement policy and retain dataset/version/source provenance.1

Delegated operations used for this result: food. Their calculation or parsing conventions apply to the corresponding result fields.2

Input fieldMeaning and unitsAccepted input
foodsFoodsRequired. Array of Object; no unknown keys.; maximum items 128.
foods[].aliasesAliasesRequired. Array of Text; minimum UTF-16 length 1; maximum UTF-16 length 128.; maximum items 32.
foods[].categoryCategoryRequired. Text; maximum UTF-16 length 256.
foods[].dataTypeData TypeRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
foods[].descriptionDescriptionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 2048.
foods[].fdcIdFdc IdRequired. Safe integer; minimum 1.
foods[].idLiteral identifier used independently of display labels.Required. Text; maximum UTF-16 length 64.
foods[].nameNameRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 512.
foods[].nutrientsNutrientsRequired. Array of Object; no unknown keys.; minimum items 1; maximum items 64.
foods[].nutrients[].amountPer100gAmount Per100gRequired. Finite number; minimum 0.
foods[].nutrients[].derivationCodeDerivation CodeRequired. Text; maximum UTF-16 length 128. or Null.
foods[].nutrients[].idLiteral identifier used independently of display labels.Required. Text; minimum UTF-16 length 10; maximum UTF-16 length 128.
foods[].nutrients[].labelSupplied display label.Required. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
foods[].nutrients[].sourceNutrientIdSource Nutrient IdRequired. Safe integer; minimum 1.
foods[].nutrients[].unitUnitRequired. Text; one of "g", "kcal", "kJ", "mg", "ug".
foods[].portionsPortionsRequired. Array of Object; no unknown keys.; maximum items 24.
foods[].portions[].descriptionDescriptionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 512.
foods[].portions[].gramsGramsRequired. Finite number; strictly above 0.
foods[].publicationDatePublication DateRequired. Text; maximum UTF-16 length 128. or Null.
foods[].sourceSourceRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
nutrientIdNutrient IdRequired. Text; minimum UTF-16 length 10; maximum UTF-16 length 128.
unitUnitRequired. Text; one of "g", "kcal", "kJ", "mg", "ug".
minimumPer100gMinimum Per100gRequired. Finite number; minimum 0.
maximumPer100gMaximum Per100gRequired. Finite number; minimum 0.
datasetIdDataset IdRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
datasetVersionDataset VersionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
sourceIdSource IdRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
selectionCountSelection CountRequired. Safe integer; minimum 1; maximum 128.
withReplacementWith ReplacementRequired. Boolean.
seedOptional numeric seed; takes precedence over context randomness. Without either, use the fixed tool.io default seed.Optional. Safe integer.
Output fieldInterpretationReturned shape
selectedFoodsSelected FoodsRequired. Array of Object; no unknown keys.; minimum items 1; maximum items 128.
selectedFoods[].aliasesAliasesRequired. Array of Text; minimum UTF-16 length 1; maximum UTF-16 length 128.; maximum items 32.
selectedFoods[].categoryCategoryRequired. Text; maximum UTF-16 length 256.
selectedFoods[].dataTypeData TypeRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
selectedFoods[].descriptionDescriptionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 2048.
selectedFoods[].fdcIdFdc IdRequired. Safe integer; minimum 1.
selectedFoods[].idLiteral identifier used independently of display labels.Required. Text; maximum UTF-16 length 64.
selectedFoods[].nameNameRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 512.
selectedFoods[].nutrientsNutrientsRequired. Array of Object; no unknown keys.; minimum items 1; maximum items 64.
selectedFoods[].nutrients[].amountPer100gAmount Per100gRequired. Finite number; minimum 0.
selectedFoods[].nutrients[].derivationCodeDerivation CodeRequired. Text; maximum UTF-16 length 128. or Null.
selectedFoods[].nutrients[].idLiteral identifier used independently of display labels.Required. Text; minimum UTF-16 length 10; maximum UTF-16 length 128.
selectedFoods[].nutrients[].labelSupplied display label.Required. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
selectedFoods[].nutrients[].sourceNutrientIdSource Nutrient IdRequired. Safe integer; minimum 1.
selectedFoods[].nutrients[].unitUnitRequired. Text; one of "g", "kcal", "kJ", "mg", "ug".
selectedFoods[].portionsPortionsRequired. Array of Object; no unknown keys.; maximum items 24.
selectedFoods[].portions[].descriptionDescriptionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 512.
selectedFoods[].portions[].gramsGramsRequired. Finite number; strictly above 0.
selectedFoods[].publicationDatePublication DateRequired. Text; maximum UTF-16 length 128. or Null.
selectedFoods[].sourceSourceRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
eligibleCountEligible CountRequired. Safe integer; minimum 1; maximum 128.
datasetIdDataset IdRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
datasetVersionDataset VersionRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
sourceIdSource IdRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 128.
randomnessReplay source and normalized 32-bit seed, or null seed for an advancing context source.Required. Object; no unknown keys.
randomness.seedOptional safe-integer replay seed; normalization and precedence are explained below.Required. Safe integer. or Null.
randomness.sourceSourceRequired. Text; one of "context", "seed".

An explicit safe-integer seed takes precedence over injected context randomness and is normalized to an unsigned 32-bit integer. With no seed and no context source, replay uses the fixed tool.io default seed. A context source must return finite values from zero inclusive to one exclusive; its advancing state must be retained separately. randomness records the source and normalized seed, or null for context. These generators are not cryptographic random sources.

json
{
  "input": {
    "foods": [
      {
        "aliases": [
          "Synthetic pulse A"
        ],
        "category": "Synthetic fixtures",
        "dataType": "Synthetic",
        "description": "Synthetic food-composition fixture A, not a published USDA record.",
        "fdcId": 1,
        "id": "usda-fdc-1",
        "name": "Synthetic pulse A",
        "nutrients": [
          {
            "amountPer100g": 21,
            "derivationCode": null,
            "id": "nutrient.protein",
            "label": "Protein",
            "sourceNutrientId": 1003,
            "unit": "g"
          }
        ],
        "portions": [
          {
            "description": "Synthetic 150 g portion",
            "grams": 150
          }
        ],
        "publicationDate": null,
        "source": "synthetic-fixtures-v1"
      },
      {
        "aliases": [],
        "category": "Synthetic fixtures",
        "dataType": "Synthetic",
        "description": "Synthetic food-composition fixture B, not a published USDA record.",
        "fdcId": 2,
        "id": "usda-fdc-2",
        "name": "Synthetic grain B",
        "nutrients": [
          {
            "amountPer100g": 12,
            "derivationCode": null,
            "id": "nutrient.protein",
            "label": "Protein",
            "sourceNutrientId": 1003,
            "unit": "g"
          }
        ],
        "portions": [],
        "publicationDate": null,
        "source": "synthetic-fixtures-v1"
      },
      {
        "aliases": [],
        "category": "Synthetic fixtures",
        "dataType": "Synthetic",
        "description": "Synthetic food-composition fixture C, not a published USDA record.",
        "fdcId": 3,
        "id": "usda-fdc-3",
        "name": "Synthetic seed C",
        "nutrients": [
          {
            "amountPer100g": 28,
            "derivationCode": null,
            "id": "nutrient.protein",
            "label": "Protein",
            "sourceNutrientId": 1003,
            "unit": "g"
          }
        ],
        "portions": [],
        "publicationDate": null,
        "source": "synthetic-fixtures-v1"
      }
    ],
    "nutrientId": "nutrient.protein",
    "unit": "g",
    "minimumPer100g": 15,
    "maximumPer100g": 30,
    "datasetId": "nutrition/synthetic-food-fixtures",
    "datasetVersion": "1",
    "sourceId": "synthetic-fixtures-v1",
    "selectionCount": 2,
    "withReplacement": false,
    "seed": 42
  },
  "output": {
    "selectedFoods": [
      {
        "aliases": [],
        "category": "Synthetic fixtures",
        "dataType": "Synthetic",
        "description": "Synthetic food-composition fixture C, not a published USDA record.",
        "fdcId": 3,
        "id": "usda-fdc-3",
        "name": "Synthetic seed C",
        "nutrients": [
          {
            "amountPer100g": 28,
            "derivationCode": null,
            "id": "nutrient.protein",
            "label": "Protein",
            "sourceNutrientId": 1003,
            "unit": "g"
          }
        ],
        "portions": [],
        "publicationDate": null,
        "source": "synthetic-fixtures-v1"
      },
      {
        "aliases": [
          "Synthetic pulse A"
        ],
        "category": "Synthetic fixtures",
        "dataType": "Synthetic",
        "description": "Synthetic food-composition fixture A, not a published USDA record.",
        "fdcId": 1,
        "id": "usda-fdc-1",
        "name": "Synthetic pulse A",
        "nutrients": [
          {
            "amountPer100g": 21,
            "derivationCode": null,
            "id": "nutrient.protein",
            "label": "Protein",
            "sourceNutrientId": 1003,
            "unit": "g"
          }
        ],
        "portions": [
          {
            "description": "Synthetic 150 g portion",
            "grams": 150
          }
        ],
        "publicationDate": null,
        "source": "synthetic-fixtures-v1"
      }
    ],
    "eligibleCount": 2,
    "datasetId": "nutrition/synthetic-food-fixtures",
    "datasetVersion": "1",
    "sourceId": "synthetic-fixtures-v1",
    "randomness": {
      "seed": 42,
      "source": "seed"
    }
  }
}

Limitations and assumptions

  • The tool consumes a supplied food snapshot; it does not download USDA records or verify their freshness. Missing nutrients exclude foods, while unit mismatch is an error rather than a conversion. Eligibility is not a dietary recommendation.
  • A replay requires the same complete input and implementation. The stated sampling convention applies within its eligible space. A finite draw does not exhaust all possible outputs; repeats remain possible unless a distinct-selection rule is explicit.
  • The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.

Alternative or Complementary methods

For a supplied example, inspect the returned construction or delegated check directly. To evaluate a consumer, also test cases chosen for its own boundaries; a generated finite corpus does not establish exhaustive coverage.

References

  1. Tool behavior and example: Random Food by Nutrient Picker — tool.io

  2. Calculation or validation: random/food — tool.io

  3. USDA FoodData Central

Similar or alternative tools

  • Macronutrient split

    Convert a calorie target and carbohydrate, protein, and fat percentage split into corresponding gram targets using the standard 4–4–9 energy factors.

  • Stratified row sample

    Sample supplied records under exact stratum quotas and replacement rules, retaining row inclusion probabilities and observed draw counts.