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에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by