Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

random

Class: prob.TruncatableDistribution
Package: prob

Generate random numbers from probability distribution object

Syntax

r = random(pd)
r = random(pd,sz1,...,szN)
r = random(pd,[sz1,...,szN])

Description

r = random(pd) generates a random number r from the probability distribution pd.

r = random(pd,sz1,...,szN) generates a sz1-by-...-by-szN array of random numbers from the probability distribution pd.

r = random(pd,[sz1,...,szN]) generates a sz1-by-...-by-szN array of random numbers from the probability distribution pd.

Input Arguments

expand all

Probability distribution, specified as a probability distribution object. Create a probability distribution object with specified parameter values using makedist. Alternatively, for fittable distributions, create a probability distribution object by fitting it to data using fitdist or the Distribution Fitting app.

Size of each dimension, specified as two or more integer values, or a vector of such values. For example, specifying 5,3,2 or [5,3,2] generates a 5-by-3-by-2 array of random numbers from the probability distribution pd.

Data Types: single | double

Output Arguments

expand all

Random number generated from the probability distribution, returned as a scalar value or an array of scalar values with the dimensions specified by sz1,...,szN.

Examples

expand all

Create a standard normal probability distribution object.

pd = makedist('Normal')
pd = 

  NormalDistribution

  Normal distribution
       mu = 0
    sigma = 1

Generate one random number from the distribution.

r = random(pd)
r =

    0.5377

Create a Weibull probability distribution object using the default parameter values.

pd = makedist('Weibull')
pd = 

  WeibullDistribution

  Weibull distribution
    A = 1
    B = 1

Generate random numbers from distribution and visualize with a histogram.

rng default  % For reproducibility
r = random(pd,10000,1);
histogram(r,100)

Create a standard normal probability distribution object.

pd = makedist('Normal')
pd = 

  NormalDistribution

  Normal distribution
       mu = 0
    sigma = 1

Generate a 2-by-3-by-2 array of random numbers from the distribution.

r = random(pd,[2,3,2])
random_make_array(:,:,1) =

   -1.0689   -2.9443    0.3252
   -0.8095    1.4384   -0.7549


random_make_array(:,:,2) =

    1.3703   -0.1022    0.3192
   -1.7115   -0.2414    0.3129

See Also

| |

Was this topic helpful?