Generated: 2026-06-12 14:13 UTC
Vendor commits: tgen dae9a10, jngen 8d1e33b

tgen vs jngen — Feature Comparison

Comparison of non-trivial generation operations. See benchmarks below.

Graphs

OperationjngentgenNotesBenchmark
Connected random graph
Yes
DocsNon‑uniform*O(n + m log n) time*
Yes
DocsNon‑uniformO(n + m log n) time
Same Prüfer tree + rejection edge add. Neither uniform over all connected labeled graphs.
jngen
1366 ms
tgen
315 ms

0.23x
n=106, m=106
Random graph with fixed n, m
Yes
DocsNon‑uniform*O(n + m log n) time*
Yes
DocsUniformO(n + m log n) time
Rejection sampling with constraint machinery.(m=n)
jngen
628 ms
tgen
294 ms

0.47x
n=106, m=106

(m=2n)
jngen
1404 ms
tgen
658 ms

0.47x
n=106, m=2×106
Skewed / stretched connected graph
Yes
DocsNon‑uniformO(n + m log n) time* if spread is O(1)Omega(n * m) time* otherwise
Yes
DocsNon‑uniformO(n + m log n) time if spread is O(1)O(n log n + m log^2 n) time otherwise
Same high-level algorithm: skewed spanning tree, then ancestor-biased extra edges. Extra edges reject duplicates; jngen resets an attempt counter on success and throws after MAX_ATTEMPTS=1000 consecutive failures, while tgen uses its unique generation framework. For large spread, tgen uses binary lifting; jngen uses trivial parent-by-parent lifting.(m=n)
jngen
757 ms
tgen
253 ms

0.33x
n=106, m=106, elongation=100, spread=2

(distinct worst)
jngen
FAILURE
tgen
507 ms
n=106, m=2n-3, elongation=100, spread=2
Bipartite graph (random / complete)
Yes
DocsUniform*O(n1 + n2 + m log(n1 * n2)) time*
Yes
DocsUniformO(n1 + n2 + m log(n1 * n2)) time
tgen: Distinct edge-index sampling. jngen: Rejection sampling. Both support optional connected generation. jngen also supports allowMulti; tgen stores simple graphs only.
jngen
214 ms
tgen
61 ms

0.29x
n1=103, n2=103, m=5×105
Directed random graph
Yes
DocsNon‑uniform*O(n + m log n) time*
Yes
DocsNon‑uniformO(n + m log n) time
tgen: Rejection with constraint machinery. jngen: Rejection sampling.(directed)
jngen
688 ms
tgen
294 ms

0.43x
n=106, m=106

(DAG)
jngen
689 ms
tgen
394 ms

0.57x
n=106, m=106
Directed acyclic random graph (DAG)
Yes
DocsNon‑uniform*O(n + m log n) time*
Yes
DocsNon‑uniformO(n + m log n) time
tgen: Randomized Kahn topological order, then rejection sampling. jngen: Rejection sampling + acyclic shuffle-orient.
jngen
689 ms
tgen
394 ms

0.57x
n=106, m=106

* Uniformity or complexity is undocumented and is inferred by code inspection.

Trees

OperationjngentgenNotesBenchmark
Random labeled tree
Yes
DocsUniformO(n) time*
Yes
DocsUniformO(n) time
Prüfer sequence.
jngen
781 ms
tgen
660 ms

0.84x
n=106
Skewed tree (wnext / Prim-like)
Yes
DocsNon‑uniform*O(n) time*
Yes
DocsNon‑uniformO(n) time
Uses parent(i) = wnext(i, elongation).
jngen
314 ms
tgen
213 ms

0.68x
n=106, elongation=100
Random tree (Kruskal-like)
Yes
DocsNon‑uniform*O(n log(n) alpha(n)) expected time*
Yes
DocsNon‑uniformO(n log(n) alpha(n)) expected time
Kruskal-like edge add until connected.
jngen
779 ms
tgen
678 ms

0.87x
n=106

* Uniformity or complexity is undocumented and is inferred by code inspection.

Lists and sequences

OperationjngentgenNotesBenchmark
Distinct values in range
Yes
DocsUniform*O(k log k) expected time*
tgen: Fisher–Yates + forbidden-value map. jngen: Hash-set rejection.
jngen
1967 ms
tgen
981 ms

0.50x
n=5×106, value_left=1, value_right=10×106
Random integer list (duplicates allowed)
Yes
DocsUniform*O(k) time*
Independent uniform draws.
jngen
92 ms
tgen
62 ms

0.67x
n=5×106, value_left=1, value_right=10×106
Uniform random permutation
Yes
DocsUniform*O(n) time*
Yes
DocsUniformO(n) time
jngen
142 ms
tgen
152 ms

1.07x
n=5×106
Declarative constraints (palindrome, cycles)NoConstraint-based uniform sampling.

* Uniformity or complexity is undocumented and is inferred by code inspection.

Math

OperationjngentgenNotesBenchmark
Partition into k parts (fast)
Yes
DocsNon‑uniform*O(k log k) time*
Same high-level approach: random delimiters, sort, gap recovery. jngen also sorts parts in non-increasing order and shuffles; tgen fast omits reordering. Not uniformly random; Optimized for speed.
jngen
659 ms
tgen
335 ms

0.51x
n=1018, k=3×106, part_left=0
Uniform ordered partition into k parts (composition)No
Yes
DocsUniformO(n) time if unbounded part_rightO(n·k) time otherwise
Stars-and-bars or DP in log space. Uniform over ordered compositions.tgen: 822 ms
n=5×107, k=10, part_left=0
Uniform ordered partition, variable number of partsNoDP in log space.tgen: 1054 ms
n=4.8×106
Random integer with congruence constraintsNo
Yes
DocsUniformO(|mods| + log r) time
Partition array into k groups
Yes
DocsUniform if unbounded max_sizeNon‑uniform otherwiseO(n) time if unbounded max_sizeO(n + k log k) time otherwise
jngen
203 ms
tgen
122 ms

0.60x
n=106, k=106

* Uniformity or complexity is undocumented and is inferred by code inspection.

Geometry

OperationjngentgenNotesBenchmark
Random convex polygon
Yes
DocsNon‑uniform*O(n log n) time*
tgen: Valtr construction filling bounding box. jngen: Hull of 10n ellipse points, subsample n. Different shape distributions. Benchmark uses the same n and max for both (wide max so jngen hull subsampling succeeds at n=1e6).
jngen
2830 ms
tgen
953 ms

0.34x
n=106, min=0, max=3×1010
Points in general position (no three collinear)
Yes
DocsNon‑uniform*O(n² log n) expected time*
tgen: Algebraic construction over F_p. jngen: Rejection until no collinearity.(n=1800)
jngen
2010 ms
tgen
11 ms

<0.01x
n=1800, min=0, max=3×106

(n=1e6)
jngen
TIMEOUT
tgen
203 ms
n=106, min=0, max=3×106
Random simple polygonNo
Yes
DocsNon‑uniformO(n log n) expected time
Points + polygonization.tgen: 1247 ms
n=106, min=0, max=3×106
Simple polygon through given pointsNo
Yes
DocsNon‑uniformO(n log n) expected time
Randomized divide-and-conquer Hamiltonian path.tgen: 1094 ms
n=106

* Uniformity or complexity is undocumented and is inferred by code inspection.

Strings

OperationjngentgenNotesBenchmark
Regex / pattern strings
Yes
DocsUniformO(output length) expected time
Same testlib-style regex syntax. tgen samples uniformly among matches (documented); jngen explicitly does not: e.g. Rnd.next("[1-9][0-9]{1,2}") does not yield uniform digit strings. Benchmark measures generation throughput at fixed pattern length, not distributional fairness.
jngen
404 ms
tgen
516 ms

1.28x
pattern=(([1-9][0-9]{3}|[A-F]{4})|(ab|cd){2}){r}, len=107

* Uniformity or complexity is undocumented and is inferred by code inspection.

Hacks

OperationjngentgenNotesBenchmark
Polynomial hash collision strings (signed mod)Deterministic collision construction, not random sampling. Both generate colliding strings for rolling hash.
Polynomial hash collision (unsigned / power-of-two mod)NoThue–Morse construction.
std::unordered_set collision inputsOverlap in purpose; Different APIs and compiler support. jngen: GCC 4.x only; Tuned load factor/reserve. tgen: GCC multiplier-based collision keys.
std::set collision stringsNoDistinct strings with equal std::set ordering keys.
Max-flow worst case (Dinitz / Edmonds-Karp)NoZadeh network.
Mo's algorithm worst-case queriesNo
Yes
DocsO(n log n + q) time
SPFA TLE graphNo
Yes
DocsO(n) time
Graph with n vertices and edges; Forces Ω(n²) relaxations.
Stale-heap Dijkstra bug graphNoForces Ω(n²) without stale-heap skip.
Non-strict relaxation Dijkstra bug graphNoForces Ω(2^{n/2}) with non-strict relaxation.
MT19937 XOR-hash collision maskNoBitmask for int or long long outputs.
Segment-tree-beats worst caseNo
Rotating calipers bug polygonNoFixed 6-vertex convex polygon.

* Uniformity or complexity is undocumented and is inferred by code inspection.

Other

OperationjngentgenNotesBenchmark
Distinct generationNo
Yes
DocsUniformO(k log n) time for k distinct values
Composable constraint machinery.
Testlib integrationNojngen is built on testlib. tgen is a standalone header with register_gen and its own constraint API.
Built-in SVG visualizationNojngen Drawer for points, segments, circles, polygons; Outputs SVG.
Accelerated build guideNoCompile jngen.h once into a static lib; Link with JNGEN_DECLARE_ONLY for faster rebuilds.

Samples

Geometry

Operationjngentgen
Random convex polygon
Yes
DocsNon‑uniform*O(n log n) time*
n=80, min=0, max=1000
jngen sample
n=15000, min=0, max=3×109
jngen sample
n=80, min=0, max=1000
tgen sample
n=15000, min=0, max=3×109
tgen sample
Points in general position (no three collinear)
Yes
DocsNon‑uniform*O(n² log n) expected time*

n=2000, min=0, max=3×106
jngen sample

n=2000, min=0, max=3×106
tgen sample
Random simple polygonNo
Yes
DocsNon‑uniformO(n log n) expected time

n=80, min=0, max=1000
tgen sample
Simple polygon through given pointsNo
Yes
DocsNon‑uniformO(n log n) expected time

10×10 input grid, min=0, max=1000
tgen sample

* Uniformity or complexity is undocumented and is inferred by code inspection.

tgen vs jngen — Benchmarks

Timing comparison

Bar length is relative to the slower library per operation (jngen vs tgen). Ratio is colored by the faster library.

OperationParametersComparisonRatio (tgen/jngen)
graph::get_connected (m=n)Docsn=106, m=106
jngen
1366 ms
tgen
315 ms
0.23x
graph::get_connected (m=2n)Docsn=106, m=2×106
jngen
2036 ms
tgen
678 ms
0.33x
graph::gen (m=n)Docsn=106, m=106
jngen
628 ms
tgen
294 ms
0.47x
graph::gen (m=2n)Docsn=106, m=2×106
jngen
1404 ms
tgen
658 ms
0.47x
graph::gen_skewed (m=n)Docsn=106, m=106, elongation=100, spread=2
jngen
757 ms
tgen
253 ms
0.33x
graph::gen_skewed (m=2n)Docsn=106, m=2×106, elongation=100, spread=6
jngen
1836 ms
tgen
617 ms
0.34x
graph::gen_skewed (distinct worst)Docsn=106, m=2n-3, elongation=100, spread=2
jngen
FAILURE
Cannot generate random stretched graph with parameters 1000000, 1999997, 100, 2 (assertion `false' failed).
tgen
507 ms
tree::genDocsn=106
jngen
781 ms
tgen
660 ms
0.84x
tree::gen_skewedDocsn=106, elongation=100
jngen
314 ms
tgen
213 ms
0.68x
tree::gen_kruskalDocsn=106
jngen
779 ms
tgen
678 ms
0.87x
list<int>::gen (all_different)Docsn=5×106, value_left=1, value_right=10×106
jngen
1967 ms
tgen
981 ms
0.50x
list<int>::genDocsn=5×106, value_left=1, value_right=10×106
jngen
92 ms
tgen
62 ms
0.67x
geometry::random_convex_polygonDocsn=106, min=0, max=3×1010
jngen
2830 ms
tgen
953 ms
0.34x
geometry::random_points_general_position (n=1800)Docsn=1800, min=0, max=3×106
jngen
2010 ms
tgen
11 ms
<0.01x
geometry::random_points_general_position (n=1e6)Docsn=106, min=0, max=3×106
jngen
TIMEOUT
single run exceeded 5000 ms limit
tgen
203 ms
permutation::genDocsn=5×106
jngen
142 ms
tgen
152 ms
1.07x
graph::gen_bipartiteDocsn1=103, n2=103, m=5×105
jngen
214 ms
tgen
61 ms
0.29x
graph::gen (directed)Docsn=106, m=106
jngen
688 ms
tgen
294 ms
0.43x
graph::get_acyclic (DAG)Docsn=106, m=106
jngen
689 ms
tgen
394 ms
0.57x
str::genDocspattern=(([1-9][0-9]{3}|[A-F]{4})|(ab|cd){2}){r}, len=107
jngen
404 ms
tgen
516 ms
1.28x
math::gen_partition_fixed_size_fastDocsn=1018, k=3×106, part_left=0
jngen
659 ms
tgen
335 ms
0.51x
math::partition_elementsDocsn=106, k=106
jngen
203 ms
tgen
122 ms
0.60x

tgen-only timings

OperationParameterstgen
geometry::random_simple_polygonDocsn=106, min=0, max=3×1061247 ms
geometry::random_simple_polygon_through_pointsDocsn=1061094 ms
math::gen_partitionDocsn=4.8×1061054 ms
math::gen_partition_fixed_sizeDocsn=5×107, k=10, part_left=0822 ms