How to generate n independent normal random variables in Matlab - matlab

I am new to this, and I'd like to know whether there's a function or any way I can generate n independent normal random variables in Matlab?

randn will produce independent random variates from a Normal distribution.
In general, you have to trust that the sequence of variates produced by a pseudo-random number generator are statistically independent. Smart people who are experts in designing RNGs have worked hard to try to achieve that.

You can use these two below,
randn
which will give you normally distributed random numbers.
rand
which will give you uniformly distributed random numbers.

Related

Random Number From Normal Distributions in Matlab

Is randn() in Matlab actually using an inverse normal distribution to generate the random numbers from normal distributions?
This manual page says:
NormalTransform: Transformation algorithm used by randn(s, ...) to
generate normal pseudorandom values. Possible values are 'Ziggurat',
'Polar', or 'Inversion'.
You specifically asked about inversion, so I'm assuming you're already familiar with it. Here are links in case you want to know more about the Ziggurat or polar methods.

Generate Multiple random multidimensional normal distribution in MATLAB

I want to generate multiple(1000) random multidimensional(10000) normal distributions with different densities in matlab.
I know how to generate a multivariate normal distribution using mvnrnd() function but I was wondering if I could do it in a automated way. Maybe have the mean and sigma generated by rand function then feed it into the mvnrnd() function somehow?
Also would it be possible to generate some(300) of these in a hyper spherical formation where the means are distributed spherically in the multidimensional space. They should have the same density and spread/sigma.
Thank you for your input in advance.

Correct way to generate random numbers

On page 3 of "Lecture 8, White Noise and Power Spectral Density" it is mentioned that rand and randn create Pseudo-random numbers. Please correct me if I am wrong: a sequence of random number is that which for the same seed, two sequences are never really exact.
Whereas, Pseudo-random numbers are deterministic i.e., two sequences are same if generated from the same seed.
How can I create random numbers and not pseudo-random numbers since I was under the impression that Matlab's rand and randn functions are used to generate identically independent random numbers? But, the slides mention that they create pseudo random numbers. Googling for creating of random numbers return rand and randn() functions.
The reason for distinguishing random numbers from pseudo-random numbers is that I need to compare performance of cryptography (A) random with white noise characteristics and (B) pseudo-random signal with white noise characteristic. So, (A) must be different from (B). I shall be grateful for any code and the correct way to generate random numbers and pseudo-random numbers.
Generation of "true" random numbers is a tricky exercise, you can check Wikipedia on RNG and the tests of randomness (http://en.wikipedia.org/wiki/Random_number_generation). This link offers RNG based on atmospheric noise (http://www.random.org/).
As mentioned above, it is really difficult (probably impossible) to create real random numbers with computer software. There are numerous projects on the internet that provide real random numbers that are generated by physical processes (for example the one Kostya mentioned). A Particularly interesting one is this from HU Berlin.
That being said, for experiments like the one you want to perform, Maltab's psedo RNGs are more than fine. Matlab's algorithms include Mersenne Twister which is one of the best known pseudo RNG (I would suggest you google the Mersenne Twister's properties). See Maltab rng documentation here.
Since you did not mention which type of system you want to simulate, one simple approach to solve your issue would be to use a good RNG (Mersenne Twister) for process A and a not-so-good for process B.

how to generate a dataset of correlated variables with different distributions?

For teaching purposes, I need to generate random datasets of correlated random variables with different distributions. I have tried corr2data in Stata but it will not allow me to specify max and min values of the variables to be generated, just means, sd's and the covariance matrix. Therefore, I need to do messy adjustments after generation of the data. Various other details annoy me with corr2data. Is there a simpler way of doing this with MATLAB? I am not as familiar with this software as I am with Stata.
If you have access to Statistics Toolbox as well as MATLAB, you can use the copula functionality to do this fairly easily. Using a copula, you can specify the marginal distributions of each variable, and a correlation structure between the variables.
You can then generate random numbers from the copula, fit it to data etc. as well.
See in the MATLAB documentation:
Copulas: Generate Correlated Samples

Defining your own probability density function in MATLAB

Is it possible to define your own probability density function in MATLAB or Octave and use it
for generating random numbers?
MATLAB and Octave have default functions like rand, randn built in to draw points at random from a uniform, or normal distributions but there seems to be no documentation of how to define my very own proability density function.
Sampling from an arbitrary random distribution is not always trivial. For well known distributions there are tricks to implement them and most of them are implemented in stats toolbox as Oli said.
If your distribution of interest is of difficult form, there are many sampling algorithms that may help you, such as, rejection sampling, slice sampling, Metropolis–Hastings algorithm.
If your distribution is discrete, or can be approximated by a discrete distribution fairly well, then you can just do multinomial sampling using randsamp.
If you have the stats toolbox, you can use random(), as it has a lot of useful PDFs built-in.
I've had to do that a few times recently, and it's not exactly an easy thing to accomplish. My favorite technique was to use Inverse transform sampling.
The idea is quite simple:
create a cdf
use a uniform random number generator.
identify the RV that maps to your cdf value.