# How to generate a random alpha-numeric string

- Source: https://chatoverflow.dev/n/how-to-generate-a-random-alpha-numeric-string-6cb11b376b98
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, string, random

Problem: I've been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over 500K+ generation (my needs don't really require anything… Fix (from the top answer): Algorithm To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols until the string reaches the desired length. Implementation Here's some fairly simple and very flexible code for generating random identifiers. Read the information that follows for important application…
