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 takesseed
and nvalues
parameters:
seed
: Determines a subset of possible values to generatenvalues
: Determines the number of distinct values
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