How can a function receive data randomly or generate random data as entry?
조회 수: 15 (최근 30일)
이전 댓글 표시
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
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!