Random Register Bitfield Round-Trip Test Case Generator
Build a bounded reproducible register bitfield round-trip test case from explicitly supplied candidate scenarios. Every candidate must satisfy imported microcontroller/register-field-encode before selection; answer cards preserve its units, conventions, domain limitations and signed/unknown results. Draws are uniform over caller candidate positions; no replacement means no repeated positions, not necessarily distinct answers. No automatic pedagogical correctness, compliance or physical readiness. Also imports microcontroller/register-field-decode and returns actual round-trip answers; decoding errors propagate, rather than asserting success from generation alone.
Description
A register bitfield operation inserts a value into a defined offset and width.
A register bitfield operation inserts a value into a defined offset and width.1
Sampled cases preserve unaffected bits and invoke the decoder with the same field parameters for round-trip evidence.
When to use Random Register Bitfield Round-Trip Test Case Generator
Use this tool when you need to assemble reproducible practice cards from a supplied, validated scenario corpus. Prepare the seed and the exact inventory or scenario inputs described below. Keep units, reference edition, and sampling convention explicit.
How to use Random Register Bitfield Round-Trip Test Case Generator and understand its results
- Prepare the seed and the exact inventory or scenario inputs described below. Keep units, reference edition, and sampling convention explicit.
- Enter seed, count, withoutReplacement, candidateInputsJson, following the field table and calculation rules below, then run the tool.
- Read result. Inspect the nested fields in the output table below and keep any missing evidence or selected indices visible.
- Correct any input issues and run again. Before using a successful result, review its units, signs, evidence coverage, and stated model or reference assumptions.
| Input field | Meaning | Value type | Requirement |
|---|---|---|---|
| seed | Nonblank reproducibility seed; default seeded runs restart for each request | string | Required |
| count | Number of sampled entry positions | safe integer from 1 to 64 | Required |
| withoutReplacement | True draws distinct entry positions; false permits repeated positions | boolean | Required |
| candidateInputsJson | JSON strings containing full candidate input objects for the imported calculator | list of string | Required |
Enter 1–128 dense candidateInputsJson strings, each a strict JSON object for the imported calculator. Each string is at most 8192 UTF-16 units, the corpus at most 131072, and nesting at most 16 levels; nonfinite numbers and prototype-control keys are rejected. Select candidate positions under the sampling rules, then validate every candidate, including undrawn ones, by invoking the imported calculator with a fixed random source of 0.5. Any invalid candidate fails the whole request. Invoke it again for selected candidates with the request’s advancing source, and return original inputs, actual answer objects, selected indices, and never-selected indices. Duplicate candidate texts or equal answers may occur at distinct positions.2, 3, 4, 5
Use a nonblank seed of at most 256 UTF-16 units and a safe-integer count from 1 to 64. By default the seed is hashed into a deterministic pseudorandom state; each run restarts that state, so identical full inputs and implementation reproduce the result. The SDK may provide context.random, which replaces the seeded source and advances across the request; the seed remains required. Every source value must be finite in [0,1), with a request limit of 100000 source calls. Draw an index as floor(U×remainingSize). With replacement draw from the full inventory each time; without replacement remove each chosen position from an ordered pool and reject counts exceeding the inventory size. Uniform-source draws are over positions, not necessarily distinct values. This is not secure randomness.
The encoder operates on an unsigned 32-bit register with a supported offset and width, ensures the field fits within 32 bits and its value fits the width, and uses BigInt masks to preserve other bits. The decoder reads the resulting register using the original offset and width.
newRegister=(register AND NOT shiftedMask) OR (value shiftedLeft offset) Read these symbols with the field meanings and branch or reference rules above.
| Output field | Meaning | Value type |
|---|---|---|
| result | Object containing the fields below | object |
| result.baseToolId | Canonical ID of the imported calculator that produces answer cards | string |
| result.selectedCandidateIndices | Zero-based original corpus positions, in draw order | list |
| result.unusedCandidateIndices | Zero-based original corpus positions never selected | list |
| result.exercises | Selected cards with original input and actual imported answer objects | list |
| result.decoderId | Canonical ID of the decoder used for actual round-trip answers | string |
Each result.exercises entry preserves its supplied input and imported answer object. Additional roundTripAnswer, secondaryAnswer, prompts, or derived quantities appear only where the mechanics above describe them. selectedCandidateIndices and unusedCandidateIndices refer to the original corpus positions, not answer values.
{
"input": {
"seed": "tool.io/batch42",
"count": 1,
"withoutReplacement": true,
"candidateInputsJson": [
"{\"register\": 0, \"offset\": 4, \"width\": 4, \"value\": 10}"
]
},
"output": {
"result": {
"baseToolId": "microcontroller/register-field-encode",
"selectedCandidateIndices": [
0
],
"unusedCandidateIndices": [],
"exercises": [
{
"input": {
"register": 0,
"offset": 4,
"width": 4,
"value": 10
},
"answer": {
"register": 160
},
"roundTripAnswer": {
"value": 10
}
}
],
"decoderId": "microcontroller/register-field-decode"
}
}
} Limitations and assumptions
The default source is deterministic pseudorandomness, not an independently audited or secure draw. Replacement applies to inventory positions; distinct positions may render identically or yield equal answers. Review the supplied inventory or scenario domain independently before interpreting the sample. Each answer retains the imported calculator’s unit conventions and domain assumptions. Randomizing a supplied scenario does not broaden that calculator’s capabilities.
Missing required fields, unknown fields, wrong types, and violated calculation rules return input issues. Numeric values must be finite; nonfinite numeric outputs are rejected. Arrays must be dense, with no missing cells. Extremely large composite outputs are rejected.
Alternative or Complementary methods
For a related task, use Random PWM Register Exercise Generator: PWM duty counts depend on a period-register convention and a target duty fraction. Scenario cards retain that arithmetic without writing a register or establishing safe hardware timing. For a complementary step, use Random Varint Round-Trip Test Case Generator: Variable-length integer encodings use a specific byte and integer convention. Sampling supplied cases and invoking the decoder preserves actual round-trip evidence rather than asserting reversibility from the generator name.
References
-
Random Register Bitfield Round-Trip Test Case Generator — tool.io
-
Register Field Encoder — tool.io
-
Register Field Decoder — tool.io
-
Calculation or validation: random/number — tool.io
Similar or alternative tools
- Random PWM Register Exercise Generator
PWM duty counts depend on a period-register convention and a target duty fraction. Scenario cards retain that arithmetic without writing a register or establishing safe hardware timing.
- Random Varint Round-Trip Test Case Generator
Variable-length integer encodings use a specific byte and integer convention. Sampling supplied cases and invoking the decoder preserves actual round-trip evidence rather than asserting reversibility from the generator name.