Skip to content

Main content

Random Order-Preserving Queue Interleaving

Replay seed or one advancing injected source, uniform over the explicitly stated finite support, not cryptographically secure. Sample uniformly over order-preserving queue-identity interleavings by choosing next queue proportional to remaining item count; unequal queue lengths are not equal-weight queues.

Loading tool…

Description

Sample uniformly over order-preserving queue-identity interleavings by choosing next queue proportional to remaining item count; unequal queue lengths are not equal-weight queues.

A random construction is defined by its sampling support: positions, permutations, complete tilings, proposal sequences or another explicit set. Uniform choices at one stage do not necessarily make final visible outcomes uniform. A replay seed gives a deterministic sequence; equal values can hide different sampled positions. These tools are for reproducible synthetic examples rather than cryptographic entropy.

Sample uniformly over order-preserving queue-identity interleavings by choosing next queue proportional to remaining item count; unequal queue lengths are not equal-weight queues.

When to use this tool

Use this tool to sample uniformly over order-preserving queue-identity interleavings by choosing next queue proportional to remaining item count; unequal queue lengths are not equal-weight queues.

How to use the tool and how it works

  1. Enter queuesJson, seed using the definitions below. Serialize JSON text fields in the decoded shape shown below.
  2. Run the operation. Resolve input-format errors before interpreting an output.
  3. Read result.seed, result.output, using the stated boundary, ordering, sign and absence conventions.

Maintain each queue’s next position. At each step choose a queue with probability proportional to its remaining item count, emit that next item and advance only that queue. Return queue/position/value provenance for every item.1

Input fieldMeaning and unitsAccepted input
queuesJsonJSON array of string queues; the flattened nonempty sequence must have at most 128 entries.Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply.
seedNonblank replay seed, at most 256 UTF-16 code units; an injected source overrides seeded draws.Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply.

These decoded structures show the examples inside JSON text fields. Supply their serialized JSON strings as input.

json
{
  "queuesJson": [
    [
      "a",
      "b"
    ],
    [
      "c"
    ]
  ]
}
Output fieldInterpretation
resultObject containing the fields below.
result.seedOriginal supplied seed string; injected-source replay additionally requires that source’s state.
result.outputInterleaved queue records retaining queue, original position and value.
json
{
  "input": {
    "queuesJson": "[[\"a\",\"b\"],[\"c\"]]",
    "seed": "batch56"
  },
  "output": {
    "result": {
      "seed": "batch56",
      "output": [
        {
          "queue": 0,
          "position": 0,
          "value": "a"
        },
        {
          "queue": 1,
          "position": 0,
          "value": "c"
        },
        {
          "queue": 0,
          "position": 1,
          "value": "b"
        }
      ]
    }
  }
}

Limitations and assumptions

  • The nonempty flattened bank must contain at most 128 positions. Sampling is uniform over labeled order-preserving interleavings, not independent equal-probability queue choices.
  • A nonblank seed of at most 256 UTF-16 code units is required. With ordinary use the seed initializes one deterministic advancing source; an application-injected random source takes precedence and the seed alone then cannot replay the result. Uniformity statements assume independent uniform source draws in [0,1). Source calls are bounded and degenerate injected sources can fail a rejection budget. This is not cryptographically secure.
  • Every declared outer field is required and unknown outer fields are rejected. Strings and JSON text have size limits, lists are bounded to 128 entries, and JSON nesting/node counts are bounded. Tighter operation-specific bounds stated above take precedence.
  • Ordinary numeric outputs must be finite and within safe-integer magnitude. Exact large lengths/counts use decimal strings. Original record indexes and code-unit positions are zero-based; span ends are exclusive unless stated otherwise.

Alternative or Complementary methods

Choose a generator whose support matches the intended experiment and retain source-position provenance. Use a separate statistically justified process model or cryptographic source where those properties matter.

References

  1. Tool behavior and example: Random Order-Preserving Queue Interleaving — tool.io

Similar or alternative tools