2D Integer Generator

Generates a rows x columns array of random integers within a configurable [min, max] range, output as a single-line JSON-style nested array notation, e.g. "[[1,2,3],[4,5,6]]". A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

This tool generates a random two-dimensional array of integers, output as compact, code-ready JSON array notation.

Set the rows, columns, and a Min/Max range, and it prints the whole array on a single line, ready to paste directly into code or a JSON file.

What Is 2D Integer Generator?

A generator that produces a Rows x Columns nested array, every value independently and uniformly random within your [Min, Max] range.

Unlike an ASCII grid, the output is JSON-style array notation, e.g. "[[1,2,3],[4,5,6]]", which double as both a JSON value and a JavaScript array literal.

How 2D Integer Generator Works

For every position in the Rows x Columns grid, the tool draws an independent uniformly random integer between Min and Max, inclusive.

The resulting nested array is serialized with JSON.stringify, which produces compact notation with no extra whitespace.

When To Use 2D Integer Generator

Use it to generate ready-to-paste sample 2D array literals for test fixtures, seed data, or code examples.

It's also useful for quickly producing JSON test payloads shaped like a grid.

Features

Advantages

  • Output is valid JSON and a valid JavaScript array literal at the same time, so it pastes directly into code.
  • Compact single-line format that's easy to copy into a test file or API payload.
  • Supports any integer Min/Max range, including negative values.

Limitations

  • Every cell is independent, so there's no guarantee of any structural property beyond uniform randomness.
  • Rows and columns are each capped at 50 to keep generation and the resulting JSON size manageable.
  • Uses Math.random(), so it is not suitable for cryptographic or security-sensitive randomness.

Examples

A 2x3 array between 1 and 9

Input

rows=2, cols=3, min=1, max=9

Output

[[3,7,1],[9,2,4]]

A 2-row, 3-column nested array of independent random integers between 1 and 9 (exact values vary run to run).

A 2x2 array between -5 and 5

Input

rows=2, cols=2, min=-5, max=5

Output

[[-2,4],[0,-5]]

A 2x2 nested array drawn from a negative-to-positive range.

Best Practices & Notes

Best Practices

  • Use this instead of the Integer Matrix Generator when you need the output to be directly pasteable as code or JSON.
  • Keep dimensions modest if you plan to hand-edit the resulting array afterward.

Developer Notes

Each cell is computed as `min + Math.floor(rng() * (max - min + 1))` and the resulting `number[][]` is serialized with `JSON.stringify`, which naturally produces the compact, no-whitespace array notation shown in the output.

2D Integer Generator Use Cases

  • Generating ready-to-paste 2D array test fixtures for code
  • Producing sample JSON grid payloads for API testing
  • Seeding placeholder nested-array data for demos

Common Mistakes

  • Confusing this with the Integer Matrix Generator's ASCII grid output; this tool produces JSON array notation instead.
  • Setting Min greater than Max, which is rejected as invalid.
  • Requesting a grid larger than 50x50, which exceeds the supported dimension cap.

Tips

  • Paste the output directly into a JavaScript or TypeScript file as an array literal; it's already valid syntax.
  • Use the 3D Integer Generator instead if you need a triple-nested array (depth x rows x columns).

References

Frequently Asked Questions