How can a function receive data randomly or generate random data as entry?

조회 수: 15 (최근 30일)
wafa suresh
wafa suresh 2021년 6월 27일
편집: wafa suresh 2021년 7월 6일
HI. I am looking for a function which I can enter data randomly or create a random data as a entry.
I work on text steganography in picture with MATLAB. I hope you can help me.
  댓글 수: 11
wafa suresh
wafa suresh 2021년 7월 5일
Thank you so much for this example, I will test.
Scott MacKenzie
Scott MacKenzie 2021년 7월 5일
편집: Scott MacKenzie 2021년 7월 6일
For what it's worth, here's something I put together to demonstrate @Walter Roberson's comment on "pairs of letters" -- that the message will look more natural if each letter is selected considering its probability of following the previous letter. Indeed, the output looks more natural (i.e., more like English).
df = readcell('digram.txt'); % digrams+frequencies, sorted by digram
n = size(df,1); % 27x27 = 729
letters = cellfun(@(x) x(1), df(1:27:length(df(:,1)),1));
letterFreq = (sum(reshape(cell2mat(df(:,2)), 27, [])))';
csLetterFreq = [1; cumsum(letterFreq)];
diagrams = char(df(:,1));
diagramFreq = cell2mat(df(:,2));
csDigramFreq = cumsum([ones(1,27); reshape(cell2mat(df(:,2)),27,[])]);
tot = sum(letterFreq); % total frequency (~300 million)
% create random message (begin with random letter selected as per letter freq)
message(1) = letters(find(randi(tot) <= csLetterFreq, 1));
for i=2:100
idx1 = find(message(i-1) == letters); % previous letter idx
idx2 = find(randi(csDigramFreq(end,idx1)) <= csDigramFreq(:,idx1), 1) - 1; % next letter idx
message(i) = letters(idx2);
end
message = strrep(message, '_', ' ') % replace underscore with space
message = 'aghesthif be ngole tthef is s y ms jup citoses in in winomaledwethe osther h e bams sthe he corithon'

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by