Skip to content

Main content

Random Circular Buffer Wraparound Trace Generator

Simulate sampled reads and writes with delegated circular indices, explicit next-read head and next-write tail, occupancy, underflow and selected reject-or-overwrite overflow semantics.

Loading tool…

Description

Simulate sampled reads and writes with delegated circular indices, explicit next-read head and next-write tail, occupancy, underflow and selected reject-or-overwrite overflow semantics.

An operation trace pairs an ordered request stream with the state after each step. Empty operations, ties, evictions, and boundary indexes are part of the modeled contract rather than incidental display details.

Simulate sampled reads and writes with delegated circular indices, explicit next-read head and next-write tail, occupancy, underflow and selected reject-or-overwrite overflow semantics.

When to use this tool

Use this generator to create reproducible circular buffer wraparound trace 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 capacity, operations, eventCount, minimumValue, maximumValue, overflowPolicy 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 events, finalValues. Use the conventions below. Keep answer-bearing fields separate when presenting an exercise.

Sample reads and writes on a fixed circular buffer, delegating wrapped indexes. Reads remove the oldest value; full writes either reject or overwrite and evict it. Return raw cell snapshots, head/tail/size, and final logical FIFO values.1

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

Input fieldMeaning and unitsAccepted input
capacityCapacityRequired. Safe integer; minimum 1; maximum 16.
operationsOperationsRequired. Array of Text; one of "read", "write".; minimum items 1; maximum items 2.
eventCountEvent CountRequired. Safe integer; minimum 1; maximum 64.
minimumValueMinimum ValueRequired. Safe integer.
maximumValueMaximum ValueRequired. Safe integer.
overflowPolicyOverflow PolicyRequired. Text; one of "reject", "overwrite".
seedOptional numeric seed; takes precedence over context randomness. Without either, use the fixed tool.io default seed.Optional. Safe integer.
Output fieldInterpretationReturned shape
eventsEventsRequired. Array of Object; no unknown keys.; minimum items 0; maximum items 64.
events[].kindKindRequired. Text; one of "read", "write".
events[].valueValueRequired. Safe integer. or Null.
events[].acceptedAcceptedRequired. Boolean.
events[].overflowOverflowRequired. Boolean.
events[].underflowUnderflowRequired. Boolean.
events[].evictedEvictedRequired. Safe integer. or Null.
events[].headHeadRequired. Safe integer; minimum 0; maximum 15.
events[].tailTailRequired. Safe integer; minimum 0; maximum 15.
events[].sizeSizeRequired. Safe integer; minimum 0; maximum 16.
events[].cellsCellsRequired. Array of Safe integer. or Null.; minimum items 1; maximum items 16.
finalValuesFinal ValuesRequired. Array of Safe integer.; minimum items 0; maximum items 16.
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": {
    "capacity": 2,
    "operations": [
      "read",
      "write"
    ],
    "eventCount": 5,
    "minimumValue": 1,
    "maximumValue": 3,
    "overflowPolicy": "overwrite",
    "seed": 42
  },
  "output": {
    "events": [
      {
        "kind": "write",
        "value": 2,
        "accepted": true,
        "overflow": false,
        "underflow": false,
        "evicted": null,
        "head": 0,
        "tail": 1,
        "size": 1,
        "cells": [
          2,
          null
        ]
      },
      {
        "kind": "write",
        "value": 3,
        "accepted": true,
        "overflow": false,
        "underflow": false,
        "evicted": null,
        "head": 0,
        "tail": 0,
        "size": 2,
        "cells": [
          2,
          3
        ]
      },
      {
        "kind": "read",
        "value": 2,
        "accepted": true,
        "overflow": false,
        "underflow": false,
        "evicted": null,
        "head": 1,
        "tail": 0,
        "size": 1,
        "cells": [
          null,
          3
        ]
      },
      {
        "kind": "write",
        "value": 1,
        "accepted": true,
        "overflow": false,
        "underflow": false,
        "evicted": null,
        "head": 1,
        "tail": 1,
        "size": 2,
        "cells": [
          1,
          3
        ]
      },
      {
        "kind": "write",
        "value": 3,
        "accepted": true,
        "overflow": true,
        "underflow": false,
        "evicted": 3,
        "head": 0,
        "tail": 0,
        "size": 2,
        "cells": [
          1,
          3
        ]
      }
    ],
    "finalValues": [
      1,
      3
    ],
    "randomness": {
      "seed": 42,
      "source": "seed"
    }
  }
}

Limitations and assumptions

  • Equal head and tail can mean empty or full, so inspect size. Rejected operations are intentional trace events. The model is sequential and omits concurrent access, memory ordering, and real storage behavior.
  • 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 Circular Buffer Wraparound Trace Generator — tool.io

  2. Calculation or validation: microcontroller/circular-buffer-index — tool.io

Similar or alternative tools

  • Two-Table Cuckoo Hashing Trace Tool

    Trace insertion evictions, lookups and deletion in two fixed-size integer-key cuckoo tables using h1(k)=k mod m and h2(k)=floor(k/m) mod m; a kick limit rolls back the insertion and signals rehash-needed, without automatic resizing or hash-quality guarantees.

  • Random Bitset Membership Operation Trace Generator

    Generate bounded set, clear and test operations with exact unsigned words stored in increasing word order and least-significant-bit member positions, using BigInt to avoid signed 32-bit truncation.