I want to draw randomly from a Uniform Distribution defined as below by code in MATLAB :-
pd1 = makedist('Uniform','lower',-0.0319,'upper',0.0319); % X1
In MATLAB the usual command is random()
but the help file tells me its only for Guassian mixture distributions. So can it also be extended for use in Uniform Distribution or is there any other function to explicitly draw randomly for Monte Carlo Simulations.
For a uniform variable, you can use
random
as follows:But this is overly complicated, and slow:
random
analyzes the inputs and callsunifrnd
, which in turn does some checks and finally callsrand
. Instead, you can just use:In general, there are three levels of functions that can be used to create (pseudo)random numbers:
random
is a sort of common interface for generating random numbers. Based on the specified inputs it calls the appropriate function, such asunifrnd
for a uniform distribution,exprnd
for an exponential distribution, ...···rnd
":unifrnd
,exprnd
,normrnd
, ... Internally, these call some of the functions to be described next, and apply some transformation to achieve the desired distribution.rand
for a continuous uniform distribution on (0,1),randn
for a normal (Gaussian) distribution with mean 0 and variance 1, andrandi
for a uniform discrete distribution.