"use strict"; const pickRandomWeighted = require("pick-random-weighted"); const syncpipe = require("syncpipe"); let columns = { color: [ "blue", "black", "brown", "red", "yellow", "gray", "white", "pink", "purple" ], size: [ "XS", "S", "M", "L", "XL", "XXL" ], country_id: [ 1, 2, 3, 4, 5 ], store_id: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ], price: [ 2, 5.50, 12, 20, 22.50 ] }; function shuffle(arrayReference) { arrayReference.sort(() => Math.random() - 0.5); } function shuffleAllColumns() { for (let key of Object.keys(columns)) { shuffle(columns[key]); } } let printColumns = Object.keys(columns); function printItem(item) { console.log(printColumns.map((column) => item[column]).join(";")); } console.log(printColumns.join(";")); for (let i = 0; i < 200; i++) { shuffleAllColumns(); // We do this because we *don't* want an even distribution, to make the data more realistic. let weightedColumns = Object.entries(columns).map(([ key, values ]) => { return [ key, values.map((value, i) => { return [ value, i ]; }) ]; }); for (let i = 0; i < 1000; i++) { let data = syncpipe(weightedColumns, [ (_) => _.map(([ key, values ]) => { return [ key, pickRandomWeighted(values) ]; }), (_) => Object.fromEntries(_) ]); printItem(data); } }