Table Of Contents

randi

Version:
    Last Modified: March 15, 2017

    Generates random integer values in the specified range.

    Syntax

    A = randi(max)
    A = randi(max, m)
    A = randi(max, m, n)
    A = randi(max, m, n, ...)
    A = randi(max, m, n, ..., type)
    A = randi([min, max])
    A = randi([min, max], m)
    A = randi([min, max], m, n)
    A = randi([min, max], m, n, ...)
    A = randi([min, max], m, n, ..., type)

    Inputs

    max

    Upper limit of the range beginning with 1 or min. For example, randi(10) generates an integer random value greater or equal 1 and less or equal 10. max is an integer.

    m

    If you only specify m, MathScript returns a m*m square matrix with random integer values. If you also specify n or ..., m is the first dimension of the output array. For example, randi(5, 2) generates a 2*2 square matrix of random integer values greater or equal 1 and less or equal 5. randi(5, 2, 3) generates an array of random integer values greater or equal 1 and less or equal 5 with two rows and three columns.

    n

    Second dimension of the output array if you generate an array of random integer values. For example, randi(5, 2, 3) generates an array of random integer values greater or equal 1 and less or equal 5 with two rows and three columns.

    ...

    Further dimensions of the output array if you generate an array of random integer values. For example, randi(5, 2, 3, 2) generates an array of random integer values greater or equal 1 and less or equal 5 with two rows, three columns, and two levels.

    type

    Output data type of the generated array of random integer values. type is a text.

    Name Description
    'uint64' uint64
    'uint32' uint32
    'uint16' uint16
    'uint8' uint8
    'int64' int64
    'int32' int32
    'int16' int16
    'int8' int8

    min

    Lower limit of random integer values if you want to generate the random numbers from a lower limit that is different from 1. For example, randi([5, 10]) generates a random integer value greater or equal 5 and less or equal 10. randi([5, 10], [2, 3]) generates an array of random integer values greater or equal 5 and less or equal 10 with two rows and three columns.

    Outputs

    A

    Random integer value or array of any dimension of random integer values.

    Syntax Variants

    You can also enclose the parameters m, n, and ... in brackets to create n-dimensional arrays with random integer values, for example randi(10, [2, 3]) or randi([3, 7], [3, 3, 3]).

    randi(5)
    randi(5, [3,4])
    randi(5, 3, 4)
    randi([1, 5], [3, 4])
    randi(5, 3, 4,'int32')

    Where This Node Can Run:

    Desktop OS: Windows

    FPGA: This product does not support FPGA devices


    Recently Viewed Topics