Generate random CSV data with customizable columns and data types
Random CSV generator creates sample CSV files with realistic data for testing imports, data pipelines, and spreadsheet functionality. Configurable columns, data types, and row counts. Essential for QA testing and development.
Define schema: column names and data types (string, number, date, email, etc.). Generator creates specified number of rows with random values matching each column's type. Output follows CSV format with proper escaping.
Each column type has its generator: names from pools, emails from patterns, numbers in ranges, dates in spans. Handles CSV escaping for commas and quotes. Configurable: delimiter, quote character, header row, line endings.
Test CSV import functionality with varied data.
Validate data transformation pipelines.
Generate large files for load testing.
Test Excel/Sheets formulas with sample data.
const generators = {
name: () => ['John', 'Jane', 'Bob', 'Alice'][Math.floor(Math.random() * 4)],
email: () => `user${Math.floor(Math.random() * 1000)}@example.com`,
int: (min = 0, max = 100) => Math.floor(Math.random() * (max - min + 1)) + min,
date: () => new Date(Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000)
.toISOString().split('T')[0],
bool: () => Math.random() > 0.5
};
function escapeCSV(val) {
const str = String(val);
return /[",\n]/.test(str) ? `"${str.replace(/"/g, '""')}"` : str;
}
function randomCSV(schema, rows) {
let csv = schema.map(c => c.name).join(',') + '\n';
for (let i = 0; i < rows; i++) {
const row = schema.map(col => {
const gen = generators[col.type];
return escapeCSV(gen(col.min, col.max));
});
csv += row.join(',') + '\n';
}
return csv;
}
// Generate 100 rows
const schema = [
{name: 'name', type: 'name'},
{name: 'email', type: 'email'},
{name: 'age', type: 'int', min: 18, max: 65}
];
randomCSV(schema, 100);Define type generators, create rows by calling generators for each column.
Use random CSV generator for testing data imports, ETL pipelines, spreadsheet functionality, and any system that processes CSV files.
Define schema: [{name: "email", type: "email"}, {name: "age", type: "int", min: 18, max: 65}]. Each type has a generator with configurable options.