Main Content

trnd

Student's t random numbers

Description

r = trnd(nu) generates a random number from the Student's t distribution with nu degrees of freedom.

example

r = trnd(nu,sz1,...,szN) generates an array of random numbers from the Student's t distribution, where sz1,...,szN indicates the size of each dimension.

example

r = trnd(nu,sz) generates an array of random numbers from the Student's t distribution, where size vector sz specifies size(r).

Examples

collapse all

Generate a single random number from the Student's t distribution with 10 degrees of freedom.

nu = 10;
r = trnd(nu)
r = 
1.0585

Use the Student's t distribution to generate random numbers from a standard Cauchy distribution.

Step 1. Generate a vector of random numbers.

Generate a column vector containing 10 random numbers from a standard Cauchy distribution, which has a location parameter mu = 0 and scale parameter sigma = 1. Use trnd with degrees of freedom V = 1.

rng('default');  % For reproducibility
r = trnd(1,10,1)
r = 10×1

    0.2678
    1.6547
   -0.9396
    1.7322
    0.1810
   -1.3351
   -1.1529
    1.2466
    2.4647
    5.8874

Step 2. Generate a matrix of random numbers.

Generate a 5-by-5 matrix of random numbers from a standard Cauchy distribution.

r = trnd(1,5,5)
r = 5×5

   -0.7133   -0.0308   -4.7003    2.5949   -1.0194
   -0.2579   -0.2820    0.2210   -0.5767    0.1394
    0.5966    0.9806   -1.9818    3.4180    2.1367
    2.4791   12.6472   -2.2442   -0.1092    2.9031
   -1.3137    1.0985   -0.0066   10.9506    1.8792

Input Arguments

collapse all

Degrees of freedom for the Student's t distribution, specified as a scalar value or an array of scalar values.

To generate random numbers from multiple distributions, specify nu using an array. Each element in r is the random number generated from the distribution specified by the corresponding degrees of freedom in nu.

Example: [9 19 49 99]

Data Types: single | double

Size of each dimension, specified as separate arguments of integers.

If nu is an array, then the specified dimensions sz1,...,szN must match the dimensions of nu. The default values of sz1,...,szN are the dimensions of nu.

  • If you specify a single value sz1, then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, trnd ignores trailing dimensions with a size of 1. For example, trnd(5,3,1,1,1) produces a 3-by-1 vector of random numbers from the distribution with 5 degrees of freedom.

Example: 3,5

Data Types: single | double

Size of each dimension, specified as a row vector of integers.

If nu is an array, then the specified dimensions sz must match the dimensions of nu. The default values of sz are the dimensions of nu.

  • If you specify a single value [sz1], then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, trnd ignores trailing dimensions with a size of 1. For example, trnd(5,[3 1 1 1]) produces a 3-by-1 vector of random numbers from the distribution with 5 degrees of freedom.

Example: [3 5]

Data Types: single | double

Output Arguments

collapse all

Student's t random numbers, returned as a scalar value or an array of scalar values with the dimensions specified by sz1,...,szN or sz. Each element in r is the random number generated from the distribution specified by the corresponding degrees of freedom in nu.

Alternative Functionality

  • trnd is a function specific to the Student's t distribution. Statistics and Machine Learning Toolbox™ also offers the generic function random, which supports various probability distributions. To use random, specify the probability distribution name and its parameters. Note that the distribution-specific function trnd is faster than the generic function random.

  • To generate random numbers interactively, use randtool, a user interface for random number generation.

Extended Capabilities

expand all

Version History

Introduced before R2006a