Random · random

🟢 3 of 3 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    classDef ok fill:#d4edda,stroke:#28a745,color:#000
    classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
    classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
    classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
    classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
    classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
    classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
    O["Random · random<br/>🟢3"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds["random(DS, n)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp["random(comp, n)"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc["random(sc, n)"]:::ok
    end
    O --- G_ds
    O --- G_comp
    O --- G_sc
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
    click v_ds href "#form-ds"
    click v_comp href "#form-comp"
    click v_sc href "#form-sc"
    

Types

Takes number, integer · Gives number

Comes from · number, integer — 44 operators in 6 blocks 🟢44
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (17) 🟢17
Time operators (9) 🟢9
Aggregate and Analytic operators (10) 🟢10
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Goes to · number — 33 operators in 7 blocks 🟢33
General purpose operators (1) 🟢1
Numeric operators (17) 🟢17
Time operators (2) 🟢2
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Data validation operators (2) 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operators that take any scalar — 48 operators in 8 blocks 🟢48
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Forms

random(DS, n) 🟢 · number, integer → number

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

random(DS_1, 5) on a dataset: the measure is replaced by draws.

Manual:

Random, Example 1: “The operator returns a random decimal number >= 0 and <1.” The page prints 0.3582791, 0.428819 and 0.715488 only to illustrate.

Expected:

the identifiers are the page’s; Me_1 holds numbers in [0, 1) that are the same on every run.

Adaptation:

no engine can reproduce the printed draws, so Me_1 is blank in the expected file and the example is checked by that property.

script.vtl
DS_r := random(DS_1,5);
Input DS_1
Id_1Id_2Me_1
10A16.0
10B4.0
11A7.2
Expected DS_r
Id_1Id_2Me_1
10A
10B
11A

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

random(comp, n) 🟢 · number, integer → number

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

random on a component inside calc, next to the seed Me_1.

Manual:

Random, Example 2: “The operator returns a random decimal number >= 0 and <1.” The page prints 0.7545341, 0.3457166 and 0.5183224 only to illustrate.

Expected:

Me_2 holds numbers in [0, 1) that are the same on every run; the seed Me_1 (16.0, 4.0 and 7.2) is kept and compared as written.

Adaptation:

no engine can reproduce the printed draws, so Me_2 is blank in the expected file and is checked by that property.

script.vtl
DS_r  := DS_1 [ calc Me_2 := random( Me_1, 8 ) ];
Input DS_1
Id_1Id_2Me_1
10A16.0
10B4.0
11A7.2
Expected DS_r
Id_1Id_2Me_1Me_2
10A16.0
10B4.0
11A7.2

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Seed replaced by draws 🟢 pandas ✅ · DuckDB ✅
Tests:

random whose result component is the seed measure itself.

Manual:

Random: “The operator returns a random decimal number >= 0 and <1.”

Expected:

Me_1 is replaced by the draws, as any operator on components replaces a measure of the same name; no seed column is left to compare, so the expected file has the structure only and the draws are checked as numbers in [0, 1) that are the same on every run.

script.vtl
DS_r := DS_1[calc Me_1 := random(Me_1, 5)];
Input DS_1
Id_1Me_1
116.0
24.0
37.2
Expected DS_r (no data points)
Id_1Me_1

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

random(sc, n) 🟢 · number, integer → number

Single draw 🟢 pandas ✅ · DuckDB ✅
Tests:

random(SC_1, SC_2) on scalars, with SC_1 = 15 and SC_2 = 12 as in the page’s valid syntax random(15,12).

Manual:

Random: “The operator returns a random decimal number >= 0 and <1.”

Expected:

SC_r is a Number in [0, 1) that is the same on every run; a draw has no fixed value, so the expected value is null and the property is checked.

script.vtl
SC_r := random(SC_1, SC_2);
Input scalars
SC_1SC_2
1512
Expected scalars

Name

Type

Value

SC_r

Number

null

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗