Random string generation of message

I have to pass (3,’hello’) it should return random characters between the message between each pair of letters like’habceabdlghflvcxo’

답변 (2개)

Bhaskar R
Bhaskar R 2019년 11월 24일

0 개 추천

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

function out_str = rand_string_gen(np, str)
% np = numberf of positions
% str = input string
out_str = char('a'+randi([0,'z'-'a'], 1, (length(str)-1)*np+1));
out_str(1:np:end) = str;
Roger Nadal
Roger Nadal 2019년 11월 24일
it only return np-1 in string not the postion of np
function out_str = rand_string_gen(np, str)
% np = numberf of positions
% str = input string
out_str = char('a'+randi([0,'z'-'a'], 1, (length(str)-1)*(np+1)+1));
out_str(1:np+1:end) = str;
Roger Nadal
Roger Nadal 2019년 11월 26일
How to print all word in text that are together and how many time they appear one word per line order from most to least?
Walter Roberson
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
Guillaume 2019년 11월 24일

0 개 추천

function out_str = rand_string_gen(np, str)
out_str = regexprep(str, '.(?!$)', sprintf('$0${char(randi(double(''az''), 1, %d))}', np));
end

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2019년 11월 24일

댓글:

2019년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by