Random string generation of message
5 次查看(过去 30 天)
显示 更早的评论
I have to pass (3,’hello’) it should return random characters between the message between each pair of letters like’habceabdlghflvcxo’
0 个评论
回答(2 个)
Bhaskar R
2019-11-24
Assuming you are dealing with row string
function out_str = rand_string_gen(np, str)
% np = numberf of positions
% str = input string
out_str = []; % initialize output string with empty
for ii = 1: length(str)-1
ram_str = char(randi([double('a'), double('z')], 1, np));
out_str = [out_str, str(ii), ram_str];
end
% your output string out_str
out_str(end+1) = str(end);
end
5 个评论
Walter Roberson
2019-11-27
Please start a new Question for that. When you do, indicate whether you have the Text Analytics Toolbox, and define exactly what a "word" is for your purposes.
Guillaume
2019-11-24
function out_str = rand_string_gen(np, str)
out_str = regexprep(str, '.(?!$)', sprintf('$0${char(randi(double(''az''), 1, %d))}', np));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!