Random String Utility

Generate a random string. Specify length and type of characters.
Updated 20 Aug 2012

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

RANDOM_STRING - Generate a random string

When a name is needed but none is provided, never fear
RANDOM_STRING is here! As configured returns a random
set of upper case letters (default of 10 long)

value - Length of the random string to generate
default - 10
type - int
value - Type of characters to include.
1 = A-Z, 2 = a-z, 3=letters/#'s/special chars
default - 1
type - int

value - The generated random string
type - str

my_str = random_string(); % 10 upper case letters
my_str = random_string(15); % 5 upper case letters
my_str = random_string(8, 3); % 8 ascii characters

Cite As

Dan Couture (2024). Random String Utility (https://www.mathworks.com/matlabcentral/fileexchange/37853-random-string-utility), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Characters and Strings in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes