# Random number

Started by March 17, 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
 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
 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.   viralTarang Dadia 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 numberwith mean near zero. Its just that  you are using very few samples.Try increasing the number of samples and you will see mean converge tozero.If you use rand() function you will get similar result.Just a suggestion, to make use of matlab's intrinsic matrix processingcapability and to reduce use of for loop you can get same result'susinga = unifrnd (-2 , 2 , [1024,1]);Hope this helpsTarang>  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