Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Ads

Discussion Groups

Discussion Groups | Matlab DSP | Random number

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

Random number - Author Unknown - Mar 17 11:41:00 2005




Hi All,

I need generate random numbers in range like -2 to 2 ,-1.8 to 1.8 ,-1.6 to 1.6 and so on...I am doing this for N = 1024 .At present I use unifrnd in MATLAB . something like

for i=1:1:1024
a(i)=unifrnd(-2,2);
end

When I calculate the mean its near zero (actually its working fine). Can some tell me other ways of generating random numbers with mean much closer to zero. I know that we can do the same with RAND. but plz tell me the differnce between unifrnd(),rand()...and so on.

Regards
Sudhir Devarakonda




(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Random number - Tarang Dadia - Mar 17 14:11:00 2005


Sudhir,

> When I calculate the mean its near zero (actually its working fine). Can
> some tell me other ways of generating random numbers with mean much closer
> to zero. I know that we can do the same with RAND. but plz tell me the
> differnce between unifrnd(),rand()...and so on.

Its not that the function you are using is not producing random number
with mean near zero. Its just that you are using very few samples.
Try increasing the number of samples and you will see mean converge to
zero.

If you use rand() function you will get similar result.

Just a suggestion, to make use of matlab's intrinsic matrix processing
capability and to reduce use of for loop you can get same result's
using

a = unifrnd (-2 , 2 , [1024,1]);
Hope this helps
Tarang

> for i=1:1:1024
> a(i)=unifrnd(-2,2);
> end
> When I calculate the mean its near zero (actually its working fine). Can
> some tell me other ways of generating random numbers with mean much closer
> to zero. I know that we can do the same with RAND. but plz tell me the
> differnce between unifrnd(),rand()...and so on.
>
> Regards
> Sudhir Devarakonda >
> To





(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Random number - Viral Sachde - Mar 18 6:02:00 2005

I guess best thing to get pure random number is use time function. Try to get cpu clock cycle and it is going to be random, than reminder it from maximum allow able length... wht u suggest
some time C / matlab repeats same series of numbers.
 
viral

Tarang Dadia <t...@gmail.com> wrote:

Sudhir,

>  When I calculate the mean its near zero (actually its working fine). Can
> some tell me other ways of generating random numbers with mean much closer
> to zero. I know that we can do the same with RAND. but plz tell me the
> differnce between unifrnd(),rand()...and so on.

Its not that the function you are using is not producing random number
with mean near zero. Its just that  you are using very few samples.
Try increasing the number of samples and you will see mean converge to
zero.

If you use rand() function you will get similar result.

Just a suggestion, to make use of matlab's intrinsic matrix processing
capability and to reduce use of for loop you can get same result's
using

a = unifrnd (-2 , 2 , [1024,1]);
Hope this helps
Tarang

>  for i=1:1:1024
>      a(i)=unifrnd(-2,2);
>  end
>  When I calculate the mean its near zero (actually its working fine). Can
> some tell me other ways of generating random numbers with mean much closer
> to zero. I know that we can do the same with RAND. but plz tell me the
> differnce between unifrnd(),rand()...and so on.

>  Regards
>  Sudhir Devarakonda





>



> To



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )