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

15 views (last 30 days)
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 Comments
Scott MacKenzie
Scott MacKenzie on 5 Jul 2021
Edited: Scott MacKenzie on 6 Jul 2021
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'

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!