Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a random string in Matlab?

Tags:

random

matlab

I want to create a string with random length and random characters, only [a-z][A-Z] and numbers. Is there something built in?

Thanks in advance.

like image 936
Cloud Harrison Avatar asked Jan 18 '12 21:01

Cloud Harrison


1 Answers

There isn't much to add to the answers of @Phonon and @dantswain, except that the range of [a-Z],[A-Z] can be generated in less painful way, and randi can be used to create integer random values.

 symbols = ['a':'z' 'A':'Z' '0':'9'];
 MAX_ST_LENGTH = 50;
 stLength = randi(MAX_ST_LENGTH);
 nums = randi(numel(symbols),[1 stLength]);
 st = symbols (nums);
like image 172
Andrey Rubshtein Avatar answered Oct 12 '22 15:10

Andrey Rubshtein