Sometimes you need to make up some random data for a sheet or a docs table just for testing in some volume. I use this snippet to generate random data in the right shape. You’ll find it in the cUseful library.

Generating test data.

Can be used like this, to get some random string data of the default size and append it as a table to the current document.

or to a sheet.

Parameters

The shape of the data can be set by like this

where

 Parameter Purpose
 ROWS  How many rows to generate
 COLUMNS  How many columns in each row
 MAX  The maximum string length in each cell
 MIN  The minimum string length in each cell

The code

A few notes on Arrays

doesn’t work as you’d expect. This is because new Array creates an array of uninitialized values which are ignored by array functions . A workaround for this is to split the array and join it again.

which will create an array whose elements are visible to array functions

The cUseful library

Many of the snippets in this section of the site are part of the cUseful library which you can include in your project.

For a comprehensive set of functions for generating random stuff, see Generating and managing random lists with JavaScript and Apps Script

For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.