Saturday, January 28, 2012

What is the difference between rand and randn in MATLAB ?

We have two functions in MATLAB namely rand() and randn() to generate random numbers.  There exists a small difference between these two which lets us easy to use but complex to understand.

rand gives value from standard uniform distribution. That is they are in range [0,1].

randn gives value from standard normal distribution. A distribution with mean 0 and variance 1 is nothing but Standard Uniform Distribution. These are also in range [0,1]

In general we will use randn for generating random numbers.





If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged

1 comment:
Write comments
  1. Not true:

    look:
    randn(2)

    ans =

    1.6035 -0.2296
    1.2347 -1.5062

    ReplyDelete