---
title: "Generating Random Data in ClickHouse"
description: "ClickHouse 22.10 added random functions for non-uniform distributions (randNormal, randBinomial, randExponential, randPoisson, randLogNormal, randBernoulli and others) alongside the existing uniform randCanonical and randUniform."
url: "https://swe.quest/articles/generating-random-data-in-clickhouse-e59cc8689ff303d4"
canonical: "https://clickhouse.com/blog/generating-random-test-distribution-data-for-clickhouse"
source: "ClickHouse"
published: "2022-12-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 13
tags: ["analytics","sql","testing"]
---

# Generating Random Data in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-12-29, 13 min read, How-to. Original: [https://clickhouse.com/blog/generating-random-test-distribution-data-for-clickhouse](https://clickhouse.com/blog/generating-random-test-distribution-data-for-clickhouse)

## Summary

ClickHouse 22.10 added random functions for non-uniform distributions (randNormal, randBinomial, randExponential, randPoisson, randLogNormal, randBernoulli and others) alongside the existing uniform randCanonical and randUniform. Combined with numbers(), these functions can populate MergeTree tables with realistic test data: exponentially distributed purchase totals, Poisson-distributed event timestamps peaking at midday, binomially shaped CPU metrics with noise, multi-modal seasonal peaks, weighted enum values and random strings. Use floor() rather than round() to get uniformly distributed integers, because rounding under-samples the range edges.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- basic probability distributions

## Keywords

ClickHouse, randNormal, randPoisson, randBinomial, randExponential, MergeTree

## Related posts

- [Native random sampling in ClickHouse](https://swe.quest/articles/native-random-sampling-in-clickhouse-b04e18e64b8c1545.md): ClickHouse · 2026-05-22 · Medium · 11 min read · Analytics & OLAP, Query engines, Performance engineering, SQL
  ClickHouse's SAMPLE clause runs aggregations over a deterministic subset of rows selected by a hash-based sample key, which must be part of the primary key so granules above the hash threshold can be skipped.
- [ClickHouse Newsletter November 2022: The purifying effects of obfuscation](https://swe.quest/articles/clickhouse-newsletter-november-2022-the-purifying-effects-of-obfuscation-ba5293e588a311a6.md): ClickHouse · 2022-11-10 · Medium · 8 min read · Analytics & OLAP, Testing, Privacy, Databases
  ClickHouse Cloud pricing now charges only for compute and storage, and ClickHouse 22.10 adds S3 backups (full and incremental), \`SET setting = DEFAULT\`, forced merging of old parts via \`min\_age\_to\_force\_merge\_seconds\`, a relaxed too-many-parts check for large partitions, new random-distribution functions and a preview Kafka Connect sink with exactly-once semantics.
- [Working with Time Series Data in ClickHouse](https://swe.quest/articles/working-with-time-series-data-in-clickhouse-d87ac55208de682a.md): ClickHouse · 2023-01-10 · Medium · 19 min read · Analytics & OLAP, SQL, Databases
  ClickHouse handles time-series workloads with Date, DateTime and DateTime64 types (up to nanosecond precision, with per-column timezones) plus SQL functions for bucketing by period. toStartOfHour and toStartOfInterval group by fixed or custom intervals, WITH FILL fills empty buckets, dateDiff builds offset rolling windows, and bar() gives quick inline visuals.
- [Decorating a Christmas Tree With the Help Of Flaky Tests](https://swe.quest/articles/decorating-a-christmas-tree-with-the-help-of-flaky-tests-286b59f771e1aae7.md): ClickHouse · 2021-12-27 · Medium · 3 min read · Testing, CI/CD, Concurrency
  ClickHouse treats flaky tests as bugs to investigate rather than noise to mute or retry, and deliberately makes tests flakier to surface hidden issues.
- [How to take random samples from big PostgreSQL tables](https://swe.quest/articles/how-to-take-random-samples-from-big-postgresql-tables-9724e6f9679558c6.md): Render · 2024-06-13 · Medium · 10 min read · PostgreSQL, SQL, Performance engineering, Query engines
  Random sampling from billion-row PostgreSQL tables with ORDER BY random() scans every row and runs a top-N heapsort, taking over a minute.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
