Random
Random data generator extension for PostgreSQL with wide range of data types
The random
extension provides a collection of functions to generate random values for various data types in PostgreSQL. It’s particularly useful for testing, data generation, and creating reproducible datasets.
Your Nile database arrives with the random
extension already enabled.
Understanding Reproducible Output
The extension is designed to generate repeatable data sets. Each function takes seed
and nvalues
parameters:
seed
: Determines a subset of possible values to generatenvalues
: Determines the number of distinct values
This allows you to generate the same set of values consistently when needed, though the order of values may vary.
Examples
String Generation
Numeric Types
Network Types
Common Use Cases
The random extension is invaluable for creating reproducible test datasets, populating development databases, generating real-looking data for demos and conducting performance testing with controlled data.
Best Practices
-
Seed Management
- Use consistent seeds for reproducible results
- Document seeds used in test scenarios
- Vary seeds systematically for different test cases
-
Value Distribution
- Consider the actual number of distinct values needed
- Account for potential PRNG collisions
- Use appropriate ranges for your use case
Additional Resources
The random extension is a powerful tool for generating reproducible data. It contains many more functions than what is shown here. To see the full list of functions, please refer to the Random Extension Repository.