Generating random data is useful when testing new use cases or benchmarking your implementation.
ClickHouse has a wide range of functions for generating random data that, in many cases, avoid the need for an external data generator.
This guide provides several examples of how to generate random datasets in ClickHouse with different randomness requirements.
Use-case: Generate a quick dataset of user events with random timestamps and event types.
rand() % 10000: uniform distribution of 10k users
arrayElement(...): randomly selects one of three event types
- Timestamps spread over the previous 24 hours
Exponential distribution
Use-case: Simulate purchase amounts where most values are low, but a few are high.
- Uniform timestamps over recent period
randExponential(1/10) — most totals near 0, offset by 15 as a minimum ([ClickHouse][1], [ClickHouse][2], [Atlantic.Net][3], [GitHub][4])
Time-distributed events (Poisson)
Use-case: Simulate event arrivals that cluster around a specific period (e.g., peak hour).
- Events peak around noon, with Poisson-distributed deviation
Time-varying normal distribution
Use-case: Emulate system metrics (e.g., CPU usage) that vary over time.
usage follows a diurnal sine wave + randomness
- Values bounded to [0,100]
Categorical and nested data
Use-case: Create user profiles with multi-valued interests.
- Random array length between 1–3
- Three per-user scores for each interest
Generating random tables
The generateRandomStructure function is particularly useful when combined with the generateRandom table engine for testing, benchmarking, or creating mock data with arbitrary schemas.
Let’s start by just seeing what a random structure looks like using the generateRandomStructure function:
You might see something like:
You can also use a seed to get the same structure every time:
Now let’s create an actual table and fill it with random data:
Let’s combine both functions for a completely random table.
First, see what structure we’ll get:
Now create the table with that structure and use the DESCRIBE statement to see what we created:
Inspect the first row for a sample of the generated data:
Last modified on July 2, 2026