Overview
Introduction
This tool generates random text designed to include surrogate-pair characters — mostly emoji — and shows exactly how many UTF-16 code units each character consumes.
It's aimed at developers debugging string-length or substring bugs that only show up with astral (above U+FFFF) characters.
What Is Random UTF-16 Generator?
A random text generator sampling from Latin letters, Greek letters, CJK ideographs, and an emoji range that lies entirely outside the Basic Multilingual Plane.
Alongside the text, it prints a per-character breakdown showing each character's code point, whether it took one or two UTF-16 code units, and the exact hex code-unit values (including the surrogate pair split, where applicable).
How Random UTF-16 Generator Works
Each character's code point is drawn from one of four ranges: Latin letters, Greek letters, CJK ideographs (all within the Basic Multilingual Plane, needing 1 code unit), or an emoji range above U+FFFF (needing a surrogate pair, 2 code units).
For code points above U+FFFF, the high and low surrogate values are computed directly: the code point minus 0x10000 is split into a 10-bit high part added to 0xD800 and a 10-bit low part added to 0xDC00.
The tool reports the assembled text, then one breakdown line per character showing its code point, code-unit count, and hex code-unit values, followed by a running total.
When To Use Random UTF-16 Generator
Use it to build test strings for validating that substring, truncation, or length-counting code correctly accounts for surrogate pairs instead of splitting them.
For a byte-oriented view, use Random UTF-8 Generator; for a pure code-point view where astral characters count as one unit, use Random UTF-32 Generator.
Often used alongside Random UTF-8 Generator, Random UTF-32 Generator and Random Unicode Text Generator.
Features
Advantages
- Deliberately includes an emoji range that always requires a surrogate pair, making it easy to reproduce surrogate-pair-related bugs on demand.
- Shows the exact high/low surrogate hex values for astral characters, useful for verifying custom UTF-16 handling code.
- Runs entirely client-side with the surrogate math computed directly, with no dependency on any particular JavaScript engine's internals.
Limitations
- The character ranges are a representative sample (Latin, Greek, CJK, one emoji block), not full Unicode coverage.
- Generated text is not semantically meaningful — it exists to exercise UTF-16 handling, not to read as coherent language.
Examples
Best Practices & Notes
Best Practices
- Use the total code-unit count, not the visible character count, when checking a system's string-length handling against expectations.
- Generate a longer sample if you specifically need multiple surrogate pairs in one test string.
Developer Notes
Surrogate-pair math is implemented directly (code point minus 0x10000, split into 10-bit high/low halves offset by 0xD800/0xDC00) rather than relying on string indexing, so the breakdown stays correct even though JavaScript strings themselves are UTF-16-encoded.
Random UTF-16 Generator Use Cases
- Testing that a substring or truncation function doesn't split a surrogate pair in half
- Verifying a custom UTF-16 encoder/decoder against known surrogate values
- Producing sample strings that reliably contain astral-plane emoji for UI rendering tests
Common Mistakes
- Assuming every character in a JavaScript string occupies exactly one string index — surrogate pairs occupy two.
- Slicing a string by raw index instead of by code point, which can produce a lone unpaired surrogate and an invalid string.
Tips
- Use Array.from(text) or a for...of loop in your own code to iterate by code point instead of by raw UTF-16 index, avoiding split surrogate pairs.
- Compare this tool's output with Random UTF-32 Generator's output to see the same text described as single code points instead.