Scilab-Branch-5.3-GIT
Change language to:
Français - 日本語 - Português

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function

# rand

random number generator

### Calling Sequence

```rand(m1,m2,.. [,key])
rand(x [, key])
rand()

rand(key)
rand("seed" [,n])
rand("info")```

### Arguments

mi

integers

key

character string with value in `"uniform"`, `"normal"`

x

a matrix. Only its dimensions are taken into account.

### Description

random matrix generator.

Warning: without a seed, the sequence will remain the same from a session to the other.

At the beginning of each script using rand function, you should use:

`rand('seed',getdate('s'))`

Without key argument the syntaxes below produce random matrices with the current random generator (default is "uniform")

rand(m1,m2)

is a random matrix of dimension `m1` by `m2`.

rand(m1,m2,..,mn)

is a random matrix of dimension `m1` by `m2`,.. by `mn`.

rand(a)

is a random matrix of same size as a. `rand(a)` is complex if `a` is a complex matrix.

rand() : with no arguments gives a scalar whose value changes

each time it is referenced.

If present, the key argument allows to specifie an other random distribution.

rand('uniform')

The current random generator is set to a uniform random generator. Random numbers are uniformly distributed in the interval (0,1).

rand('normal')

The current random generator is set to a Gaussian (with mean 0 and variance 1) random number generator.

str=rand('info')

return the type of the default random generator ('uniform' or 'normal')

IT is possible to (re-)initialize the seed of the rand generator:

rand('seed')

returns the current value of the seed.

rand('seed',n)

puts the seed to `n`. (by default `n=0` at first call).

### Remark

Use the more powerful function grand instead.

### Examples

```x=rand(10,10,'uniform')
rand('normal')
rand('info')
y=rand(x,'normal');
x=rand(2,2,2)```

### See Also

• grand — Random number generator(s)
• ssrand — random system generator
 << ones Elementary matrices sub2ind >>

 Copyright (c) 2022-2024 (Dassault Systèmes)Copyright (c) 2017-2022 (ESI Group)Copyright (c) 2011-2017 (Scilab Enterprises)Copyright (c) 1989-2012 (INRIA)Copyright (c) 1989-2007 (ENPC)with contributors Last updated:Thu May 12 11:44:13 CEST 2011