How to Use the rand (), randn (), and Randi () functions of MATLAB

Source: Internet
Author: User

1. the rand () function is used to generate values ~ 1) evenly distributed pseudo-random numbers.
Rand (n): Generate N * n 0 ~ 1. a pseudo-random matrix that satisfies the uniform distribution;
Rand (m, n): generates a pseudo-random number of M * n;
Rand (m, n, 'double'): generates double-precision pseudo-random numbers of M * n;
Rand (m, n, 'singles'): generates a single-precision pseudo-random number of M * n;
Note: 'double' and 'singles' single quotes cannot be saved.

2. The randn () function is used to generateStandardA pseudo-random number with a normal distribution.
Usage: 1.
 

3. The Randi () function is used to generate a pseudo-random integer with a uniform distribution in the range of (Imin ~ IMAX) (open interval). If Imin is set to default, the default value is 1.
Randi (IMAX, 1) or Randi (IMAX): generates 1*1 pseudo random integer smaller than IMAX;
Randi (IMAX, n): generates a pseudo-random matrix N * n Less Than IMAX;
Randi (IMAX, m, n) or Randi (IMAX, [M, N]): generates a pseudo-random matrix of M * n;
Randi (IMAX, M, N, P ,...) or Randi (IMAX, [M, N, P,...]): Generate M * n * p *... pseudo-Random matrix;
Randi (IMAX, size (a): generates a pseudo-random matrix with the same dimension as;
Randi ([Imin, IMAX], n): generates a pseudo-random matrix of N x n with the value range of [Imin, IMAX.
NOTE: If Imin exists, [Imin, IMAX] square brackets cannot be default.

Original article: 79165966

How to Use the rand (), randn (), and Randi () functions of MATLAB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.