I am a little bit confuse about use of rand() and unifrnd() in interval [0,1]. How are both different? Definitions of these from Matlab tutorial are as follows:
rand() - Uniformly distributed pseudorandom numbers 
unifrnd() - Continuous uniform random numbers  
                r = unifrnd( a , b , sz ) generates an array of uniform random numbers, where the size vector sz specifies size(r) .
By default, rand returns normalized values (between 0 and 1) that are drawn from a uniform distribution. To change the range of the distribution to a new range, (a, b), multiply each value by the width of the new range, (b – a) and then shift every value by a.
I assume you mean unifrnd, (not "unifrand").
unifrnd is part of the Statistics Toolbox, whereas rand is a Matlab basic function.
unifrand is just a wrapper of rand that lets you specify additional parameters to define the interval of the random values (rand outputs values in [0,1]). You could do the same with rand using (a-b)*rand(...)+b, where a and b is the desired interval. Type open unifrnd in Matlab to see unifrnd's code.
Another difference is that, in recent Matlab versions, rand lets you specify the data type of the generated output: single or double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With