如何在Matlab中生成随机字符串? [英] How can I generate a random string in Matlab?

查看:1744
本文介绍了如何在Matlab中生成随机字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个具有随机长度和随机字符的字符串,仅包含[a-z] [A-Z]和数字.有内置的东西吗?

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

谢谢.

推荐答案

@Phonon和@dantswain的答案没有什么可添加的,除了可以在以下位置生成[a-Z][A-Z]的范围randi可用于创建整数随机值.

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);

这篇关于如何在Matlab中生成随机字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆