matlab code for pseudo random

5 次查看(过去 30 天)
marie lasz
marie lasz 2020-12-8
评论: Rik 2020-12-8
hello,
Maybe I am asking a very dumb question here but I would like to confirm if I am thinking it right or not. this code is generating some pseudo random noise (please correct me if I am wrong) , so the question is what is this _key.bmp image file , I mean any grayscale image can I read here? I know by this file we are actually generating a key here, so what can be alternate solution here maybe?
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',key);
% generate PN sequence
pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));

回答(1 个)

Rik
Rik 2020-12-8
This looks like a fairly fragile setup to share an encryption key.
Any file that results in a valid state value can be used. By setting the state you make the next calls to random functions return predictable output. So if I use the same state on my copy of the same release of Matlab I will get the same results as you.
  2 个评论
marie lasz
marie lasz 2020-12-8
so is it better to add any key rather than adding file and that key we can use in returning the same random sequence?
Rik
Rik 2020-12-8
The file is the key. My point is only that you are relying on the random number generator being the exact same between two users. If you're only using it for an example that would be fine, but if you're actually using it for something important you should either use a completely different setup, or make sure you're using the exact same release-update combination.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by