DEV Community

Vincent
Vincent

Posted on

Random Address Generator: What a Good One Actually Generates

Random Address Generator: What a Good One Actually Generates

Subtitle: A real city, state and ZIP that agree, an invented street, and a phone number that cannot ring — the anatomy of a fake address that survives validation.


Search for "random address generator" and you get dozens of tools that all promise the same thing. They are not the same thing. Under the hood there are three kinds, and only one of them produces addresses you would want in a test database.

String mashers pick a street from one list, a city from another and a ZIP from a third. Each field looks fine on its own; together they describe a place that does not exist and never could — a Miami street in Seattle with an Ohio ZIP.

Real-address scrapers copy addresses that exist. The output validates perfectly, because it is somebody's home. That is not test data; that is a privacy problem you have just imported into your fixtures.

Structured generators do the harder thing: a real city, a real state and a real ZIP code that genuinely belong together, wrapped around a street and house number that are invented. The container is real; the contents are fiction. That is what "random address" should mean, and it takes real postal data to do it.

What a US address is made of

USPS Publication 28, the Postal Addressing Standards, defines a domestic address as stacked lines: a recipient line, a delivery address line that locates the point (house number, street name, suffix, any apartment or suite), and a last line that routes it: city, two-letter state abbreviation, ZIP code.

The abbreviations are a published standard, not a convention. Over 200 suffix variants standardise onto a small set — AVENUE, AVENU and AV all become AVE; BOULEVARD becomes BLVD; APARTMENT becomes APT — and address-validation APIs rewrite whatever you typed into that canonical form. If a generated address round-trips through a validation API unchanged, it was already well-formed.

The ZIP code is the part that has to be right

ZIP digits are not random; they encode geography. The first digit places the address in one of ten national zones, running from 0 in New England to 9 on the Pacific. The first three digits identify a sectional center facility. The full five digits name a delivery area.

The consequence is that a ZIP code and a state can contradict each other, and validators check for it. I counted the GeoNames US postal dataset: 40,977 ZIP codes under 911 three-digit prefixes across the 50 states and DC. Exactly five prefixes cross a state line — 063 (Connecticut and New York), 205 (DC, Maryland, Virginia), 726 (Arkansas and Missouri), 739 (Oklahoma and Texas), 834 (Idaho and Wyoming). Every other prefix implies one state. Only 25 of the 51 jurisdictions can be described as a single contiguous range; the rest need a set.

Two boundary values matter for anyone testing address forms: 00000 and 99999 are unassigned and always will be, so they are the canonical invalid inputs. The lowest real code is 00501, an IRS facility in Holtsville, New York — which a range check starting at 01000 wrongly rejects.

The recipe for a valid-but-fictional address

A structured generator works in this order:

  1. Pin the state. Everything downstream depends on it.
  2. Pick a real city in that state.
  3. Draw a ZIP from that state's real prefixes, so the last line passes the consistency check that fraud systems and good validators run. Handle the five cross-border prefixes as sets, not ranges.
  4. Invent the street and house number. This is the step that keeps the result fictional: the line parses and formats, and it resolves to no residence.
  5. Make the other fields agree. The area code should belong to the state; the phone number should come from 555-0100 to 555-0199, the block the North American Numbering Plan reserves for fiction; the email should be at example.com, example.net or example.org, which publish a null MX record and cannot receive mail.

The US Postal Service delivered to 170.4 million delivery points in fiscal year 2025. A good generated address fits convincingly into that space without occupying a point in it.

The classic bug, and the fixtures that catch it

The most common failure in cheap generators is three individually valid fields that contradict each other. It is also the most common failure in the forms that consume them, because a form that never sees a mismatched address never learns to reject one.

The five cross-state prefixes are the fixtures to start with. A prefix-to-state lookup passes every test you write against the other 906 prefixes and then rejects a real address in the capital region, where 205 covers Washington, DC plus exactly one code each in Maryland and Virginia. Add 00501, 00000 and 99999, and a ZIP+4 (12345-6789) to check the hyphenated form is treated as one field, and you have covered the ways ZIP arithmetic betrays you.

Outside the US, the shape changes

Most countries write addresses specific-to-general — street, then city, then region — but Japan writes them largest-unit-first. The postcode sits after the state in the US, Canada and Australia, before the city in Germany, France and Belgium. A UK postcode is alphanumeric (SW1A 1AA), a Canadian one starts with a forward sortation area (M5V), a German PLZ is five digits. A generator that only knows the US format produces nonsense the moment you pick another country; one built on each country's own postal data does not.

Who uses one, and for what

  • QA engineers fill address fields in fixtures and exercise validation. The useful feature is a seed: the same seed returns the same addresses, so a fixture can be committed and regenerated exactly.
  • Developers want an API and CSV/JSON export rather than a web page — a thousand state-valid addresses in one call.
  • Designers need believable text in mockups and screenshots without a real person's street in the frame.
  • Privacy-conscious users fill forms that will never ship anything and have no business knowing where they live.

Where the line is

Generating a fictional address is legal everywhere. Using one to deceive someone who relies on it is not: shipping goods you do not intend to pay for, dodging tax with a fake billing address, a residence on a government form, a KYC check at a bank. The address being "generated" changes nothing about that. A well-built generator makes the honest uses safe and the dishonest ones pointless — the phone cannot ring, the email cannot deliver, and the street is not there.

A seven-point checklist

Before you trust a random address generator with your test data, check that it:

  1. pairs a real city and state with a ZIP from that state's actual prefixes;
  2. invents the street and house number rather than copying a real one;
  3. matches the area code to the state and uses the 555-01XX range;
  4. uses email domains that cannot receive mail;
  5. knows other countries' formats, not just the US one;
  6. accepts a seed so results are reproducible;
  7. exports CSV and JSON, or has an API.

I built Fakenamely's random address generator to pass all seven, with a page per US state that lists the state's real ZIP prefixes and area codes. The long versions of everything above: how free address generators build fictional addresses, the US address format explained, and US ZIP code statistics, with every number computed from the GeoNames dataset.


Vincent builds Fakenamely, a free generator and keyless API for fictional test identities whose city, state and ZIP code agree with each other.

Top comments (0)