random(100px, 200px, 50px) has three equally likely outcomes: 100px, 150px and 200px. random-item(–card-size, 100px, 150px, 200px) also chooses among three entries, but each entry is a listed token sequence and the key is required by the draft grammar. Replacing a numeric range with a list changes what can be expressed and when validity is checked.
This lesson continues The Gold Standard of Websites, the Gold Standard of Education and the How X Works hub. Every range, key, option list, sampled result and computed value is an original synthetic fixture. The lesson does not promise shipping support, infer cryptographic randomness or use CSS-generated values for security, fairness, billing or durable identity.
Record function grammar, key, scope modifiers, range types, step, option tokens, base random value sharing, chosen value or index, destination parsing, inheritance, browser build and unavailable behavior.
The CSS Values and Units Module Level 5 defines random() and random-item(), their evaluation rules and their random-key sharing model. The draft says the exact random-number generator is user-agent defined and must not be relied on for cryptographic quality. It is an early-exploration editor’s draft with expected breaking changes; examples demonstrate the model rather than universal browser support.
THE GOLD STANDARD · WEBSITES
random() samples a typed numeric range; random-item() selects one listed token sequence
The proposed random() math function returns a value between typed minimum and maximum calculations, optionally restricted to a step. random-item() instead selects uniformly from a list of arbitrary CSS token sequences and substitutes the chosen item at computed-value time. They share random-key rules for deciding when a base random value is reused, but their domains, validation and failure modes differ.
Fast route
Start with the decisive rule.
Start this route
Measurement route
Build the browser state and evidence ledger.
Start this route
Comparison route
Separate the nearest lookalikes.
Start this route
Transfer route
Change the context and retest.
Start this route
Reporting route
State limits and continue reading.
Start this route
Chapter contents
Open the full chapter index
- 1. Give range and list different jobs
- 2. Check typed range consistency
- 3. Read inclusive limits
- 4. Understand stepped outcomes
- 5. Do not assume the maximum is reachable
- 6. Read item options as token sequences
- 7. Keep the random-item key required
- 8. Use auto deliberately
- 9. Use named sharing deliberately
- 10. Use element and property scope carefully
- 11. Separate choice from destination validity
- 12. Trace inheritance after evaluation
- 13. Keep randomness out of identity
- 14. Test distribution with limits
- 15. Treat unsupported syntax honestly
- 16. Repair the visual-noise shortcut
- 17. Build a reproducible random ledger
- 18. Use Values Level 5 and continue
1. Give range and list different jobs
random() maps a random base value into a numeric interval. random-item() maps it to one option index and returns that option’s token sequence.
Original worked example. A card width samples 100px to 200px while its border style chooses solid or dashed. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Replace the border list with numeric widths. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record numeric result and chosen option index separately. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
2. Check typed range consistency
random() arguments must resolve to a consistent numeric type. A length and an angle do not form a valid interval.
Original worked example. random(50px, 10rem) can resolve to a length after unit conversion. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Change the maximum to 180deg. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Inspect parse and computed-value failure. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
3. Read inclusive limits
The draft makes minimum and maximum inclusive, subject to the range and step rules. A sampled result can equal either bound.
Original worked example. random(0, 1) may resolve to zero or one. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Set the maximum below the minimum. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Capture the normalized range and result. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
4. Understand stepped outcomes
The optional step restricts outcomes to min plus an integer multiple of step. It is not ordinary rounding after continuous sampling.
Original worked example. random(100px, 200px, 50px) gives each of three outcomes equal probability. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Compare round(random(100px,200px),50px). State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Show the different probability mass at endpoints. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
5. Do not assume the maximum is reachable
When the interval is not an integer number of steps, the maximum may not be an outcome. Precision handling only repairs very close intended endpoints.
Original worked example. random(100px,200px,30px) ends at 190px. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Use a 25px step. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Enumerate reachable outcomes before testing frequencies. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
6. Read item options as token sequences
random-item() options can be arbitrary declaration-value sequences, not just numbers. A chosen option is substituted and then parsed in context.
Original worked example. font-family chooses between two comma-containing family lists. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Use brace wrapping around lists with commas. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Archive pre- and post-substitution token streams. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
7. Keep the random-item key required
The current draft requires a random-key for random-item() to avoid ambiguity between a key and the first arbitrary option. random() can omit its key and behave as auto.
Original worked example. random-item(–theme, serif, sans-serif) names the sharing key. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Remove the first argument. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record grammar validity before sampling. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
8. Use auto deliberately
An omitted random() key behaves as auto and is designed for maximum variation across instances, properties and elements under the draft’s sharing rules.
Original worked example. Width and height on each card vary independently. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Use a shared named key. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Compare which calls reuse the same base value. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
9. Use named sharing deliberately
A named key can cause multiple random functions to share a base value. Shared base does not mean identical typed outputs when mappings differ.
Original worked example. Width and hue reuse one base but map it to different ranges. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Give the hue a different key. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Save key, base relationship and final values. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
10. Use element and property scope carefully
Scope modifiers alter whether values vary per element or per property. They are not selectors and do not change the matched element set.
Original worked example. element-scoped makes one element share related values while siblings differ. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Switch to property-scoped. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record element, property and key tuple. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
11. Separate choice from destination validity
random-item() is an arbitrary substitution function. A chosen token sequence can make the destination property invalid.
Original worked example. width chooses either 10px or red; selecting red invalidates the declaration. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Replace red with auto. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Track chosen index and final property validity. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
12. Trace inheritance after evaluation
The draft evaluates at computed-value time and children inherit the resolved value where the property inherits, rather than independently rerolling the same inherited declaration.
Original worked example. A parent chooses a font family and children inherit it. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Give each child its own declaration. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record evaluation site and inherited result. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
13. Keep randomness out of identity
User-agent-defined random generation and caching are unsuitable for account identifiers, security tokens, lotteries or auditable allocation.
Original worked example. A decorative rotation may vary; an access code may not. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Move the same value into a data attribute used by script. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Reject any correctness claim that depends on CSS randomness. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
14. Test distribution with limits
A short run cannot prove uniformity, independence or cryptographic quality. Enumeration and key-sharing checks come before frequency summaries.
Original worked example. Ten thousand stepped samples roughly balance three outcomes. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Repeat with a shared key that intentionally duplicates values. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Report sample size and dependency structure. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
15. Treat unsupported syntax honestly
A dropped random function is unavailable, not a sample equal to zero or the first item. Essential styling needs a baseline declaration.
Original worked example. A fixed transform remains when the random declaration is ignored. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Run a supporting build with the same fixture. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record parser support and computed serialization. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
16. Repair the visual-noise shortcut
A varied page does not prove independent random values. Variation can come from deterministic selectors, DOM order or animation.
Original worked example. Cards appear varied from nth-child rules without random(). The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Remove those rules while keeping random functions. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Inspect matched declarations and keys. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
17. Build a reproducible random ledger
Preserve grammar, key, scope, range or options, reachable outcomes, chosen result, destination validity and inheritance.
Original worked example. The matrix covers auto, named, element-scoped, property-scoped, invalid-type and invalid-option cases. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Repeat after insertion and reordering. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Version the draft and browser. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
18. Use Values Level 5 and continue
Values Level 5 owns both random functions; the neighboring articles own substitution, tree counting and invalid values.
Original worked example. The route follows grammar, sharing, mapping, substitution and computed result. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. When caching semantics change, rerun every sharing control. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Save source URL, access date and raw computed styles. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Grouped reading routes
Core route
Companion lessons
- Separating first-valid() Candidate Parsing from var() Token Fallback
- Separating CSS if() Conditional Values from @supports Rule Gating
- Separating progress() Normalization from calc() Arithmetic
Related specialist lessons
Sources and further study
CSS Values and Units Module Level 5. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
CSS Values and Units Module Level 4. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
CSS Custom Functions and Mixins Module Level 1. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
The worked examples and transfer checks are developed here and state their own assumptions. The linked sources support the underlying CSS parsing, substitution, evaluation and cascade principles.
Return to contents · Return to The Gold Standard of Websites