Random String Generator: Numbers & Letters Explained

How-to basics · Updated November 26, 2026

Yes, you can generate a random string of numbers and letters using online tools, programming languages, or spreadsheet functions like Excel’s RANDARRAY and CHAR. The most direct method in Excel for Microsoft 365 is to enter =CONCAT(CHAR(RANDARRAY(8,1,48,90,TRUE))) in a cell to produce an 8-character alphanumeric string (though this includes some punctuation; for letters and numbers only, see below).

What Is a Random Alphanumeric String?

An alphanumeric string is a sequence of characters drawn from the set of letters (A–Z, a–z) and digits (0–9). A random string means each character is chosen independently, with no predictable pattern. For example, K7fQ2pZ9 is a random 8-character string. Random strings are used for passwords, session tokens, unique IDs, CAPTCHAs, and test data. The key property is unpredictability: no one should be able to guess the next character or the entire string from previous ones.

How Randomness Works in Practice

True randomness is hard to achieve on a computer. Most generators use a pseudorandom number generator (PRNG), which starts from a seed value and produces a sequence that appears random but is deterministic. For security-critical uses (like passwords), you need a cryptographically secure PRNG, which is seeded with entropy from system events (mouse movements, keystroke timings, hardware noise). Online tools and programming languages often use such secure sources. In Excel, the RAND and RANDARRAY functions are not cryptographically secure; they are fine for simulations or non-security testing but not for passwords.

How to Generate in Excel (Step-by-Step)

For Microsoft 365 or Excel 2021, you can use dynamic array functions. To generate a random string of letters and numbers (no punctuation) of length n, follow these steps:

  1. Decide the length, say 10 characters.
  2. In a cell, enter the formula that creates an array of 10 random numbers between 65 and 90 (uppercase A–Z) or 97 and 122 (lowercase a–z) or 48 and 57 (digits). A common trick is to use RANDARRAY to get numbers across the full ASCII range, then filter out punctuation, but that is complex. Instead, use a simpler approach: generate a random number that maps to a set of 62 characters.
  3. Use this formula (assuming you want a 10-character string in cell A1):
    =CONCAT(INDEX(CHAR(SEQUENCE(62)+48), RANDARRAY(10,1,1,62,TRUE)))
    But this includes characters like : (58) and ; (59) because the ASCII codes 58–64 are punctuation. To exclude them, you need a more complex formula. A reliable method is to use a helper column or a LET function.

Here is a clean formula that generates only letters and numbers (length 10, in cell A1):

=LET(chars, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", CONCAT(INDEX(MID(chars, SEQUENCE(62), 1), RANDARRAY(10,1,1,62,TRUE))))

This works by creating a string of all 62 allowed characters, splitting it into an array, then randomly picking 10 of them. Press Enter and you get a random string like aB3xY7qL2p. To change the length, replace the 10 in RANDARRAY(10,1,...) with your desired length. On Mac, the same formula works in Excel for Microsoft 365. In Excel for the web, dynamic arrays are supported, but the formula may need to be entered with Ctrl+Shift+Enter in older versions; in current versions, just Enter.

How to Choose a Generator Method

Your choice depends on your need:

  • Quick one-off string: Use an online random string generator (e.g., random.org). They are free and easy, but be cautious with sensitive data—check the site’s privacy policy.
  • Programming: In Python, use secrets.choice for secure strings. In JavaScript, use crypto.getRandomValues. These are cryptographically secure.
  • Spreadsheet: Excel formulas are fine for non-security uses like test data. For passwords, use a dedicated password manager.
  • Command line: On Linux/macOS, you can use openssl rand -base64 12 (gives letters, numbers, +, /, =). For alphanumeric only, use tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10.

Common Problems and Misconceptions

One common mistake is using RAND() in Excel and concatenating results, which can produce duplicates or not enough characters. Another is assuming that a random string is unique—randomness does not guarantee uniqueness; two generated strings could be identical (though unlikely for long lengths). For unique IDs, you need a UUID or a database sequence. Also, many people think that a longer string is always more secure, but the character set matters too: a 10-character string with only lowercase letters has fewer possibilities than a 10-character string with uppercase, lowercase, and digits. The misconception that “random” means “no repetition” is false; repetition is allowed unless you explicitly avoid it.

Costs and Safety Considerations

Most random string generators are free. Online tools may have limits on length or frequency for free accounts. For security, never use a non-cryptographic generator for passwords, API keys, or tokens. Also, avoid using random strings that you copy from a website for sensitive accounts—they may be logged. For passwords, use a password manager that generates secure strings locally. In Excel, the RAND function is not secure enough for passwords because it is seeded with the system clock and is predictable. If you must generate a password in Excel, use a VBA macro with Rnd combined with a random seed, but even that is not cryptographically strong; it is better to use a dedicated tool.

Alternatives to Random Strings

If you need unique identifiers, consider using a UUID (Universally Unique Identifier) like 550e8400-e29b-41d4-a716-446655440000. UUIDs are 128-bit numbers typically displayed as 32 hexadecimal digits. They are designed to be unique across space and time. For database primary keys, auto-increment integers are simpler. For human-readable codes, you might use a sequential number with a check digit (like ISBN). Random strings are not ideal for all purposes; sometimes you need a predictable format.

Frequently Asked Questions

Can I generate a random string without punctuation in Excel?

Yes, use the LET formula provided above, which restricts the character set to A-Z, a-z, and 0-9. The formula builds a string of 62 allowed characters and randomly selects from them, so you never get punctuation.

Is the random string from an online generator safe for passwords?

It depends on the generator. If it uses a cryptographically secure PRNG (like random.org, which uses atmospheric noise), it is safe. However, be aware that the string may be transmitted over the internet, so avoid using it for critical accounts if you are on an untrusted network. For maximum safety, generate passwords locally.

How do I make a random string in Python?

Use the secrets module for security: import secrets; import string; alphabet = string.ascii_letters + string.digits; ''.join(secrets.choice(alphabet) for _ in range(10)). This gives a 10-character secure random string.

What is the difference between random and unique?

Random means each character is chosen independently, so the same string could appear twice by chance. Unique means no two strings are the same. For unique strings, use a UUID or a database sequence with a unique constraint.

Can I generate a random string in Google Sheets?

Yes, Google Sheets has =RANDARRAY() and =CHAR(), but the functions differ slightly. You can use a similar LET-like approach with ARRAYFORMULA and JOIN. For example: =JOIN("", ARRAYFORMULA(INDEX(SPLIT("A B C ...", " "), RANDARRAY(10,1,1,62,TRUE)))) – but that requires a list of characters. Simpler: use a script or an add-on. For security, Google Sheets is not ideal for passwords either.

How long should a random string be?

For passwords, use at least 12 characters if it includes uppercase, lowercase, and digits. For session tokens, 128 bits (about 22 base64 characters) is typical. The length depends on the threat model; longer is generally safer, but usability matters.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.