You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/stdlib/base.rst
+11-19
Original file line number
Diff line number
Diff line change
@@ -3932,43 +3932,35 @@ Random Numbers
3932
3932
3933
3933
Random number generation in Julia uses the `Mersenne Twister library <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT>`_. Julia has a global RNG, which is used by default. Multiple RNGs can be plugged in using the ``AbstractRNG`` object, which can then be used to have multiple streams of random numbers. Currently, only ``MersenneTwister`` is supported.
3934
3934
3935
+
Most functions related to random generation accept an optional ``AbstractRNG`` as the first argument, ``rng`` , which defaults to the global one if not provided. Morever, some of them accept optionally dimension specifications ``dims...`` (which can be given as a tuple) to generate arrays of random values.
3936
+
3937
+
A ``MersenneTwister`` RNG can generate random numbers of the following types: ``Float16, Float32, Float64, Bool, Int16, Uint16, Int32, Uint32, Int64, Uint64, Int128, Uint128`` (or complex numbers or arrays of those types). Random floating point numbers are generated uniformly in [0,1).
3938
+
3935
3939
.. function:: srand([rng], [seed])
3936
3940
3937
-
Reseed the random number generator. If a ``seed`` is provided, the RNG will give a reproducible sequence of numbers, otherwise Julia will get entropy from the system. The ``seed`` may be a non-negative integer, a vector of ``Uint32`` integers or a filename, in which case the seed is read from a file. If the argument ``rng`` is not provided, the default global RNG is seeded.
3941
+
Reseed the random number generator. If a ``seed`` is provided, the RNG will give a reproducible sequence of numbers, otherwise Julia will get entropy from the system. The ``seed`` may be a non-negative integer, a vector of ``Uint32`` integers or a filename, in which case the seed is read from a file.
3938
3942
3939
3943
.. function:: MersenneTwister([seed])
3940
3944
3941
3945
Create a ``MersenneTwister`` RNG object. Different RNG objects can have their own seeds, which may be useful for generating different streams of random numbers.
3942
3946
3943
-
.. function:: rand() -> Float64
3947
+
.. function:: rand([rng], [t::Type], [dims...])
3944
3948
3945
-
Generate a ``Float64`` random number uniformly in [0,1)
3949
+
Generate a random value or an array of random values of the given type, ``t``, which defaults to ``Float64``.
3946
3950
3947
3951
.. function:: rand!([rng], A)
3948
3952
3949
-
Populate the array A with random number generated from the specified RNG.
3950
-
3951
-
.. function:: rand(rng::AbstractRNG, [dims...])
3952
-
3953
-
Generate a random ``Float64`` number or array of the size specified by dims, using the specified RNG object. Currently, ``MersenneTwister`` is the only available Random Number Generator (RNG), which may be seeded using srand.
3954
-
3955
-
.. function:: rand(dims or [dims...])
3956
-
3957
-
Generate a random ``Float64`` array of the size specified by dims
3958
-
3959
-
.. function:: rand(t::Type, [dims...])
3960
-
3961
-
Generate a random number or array of random numbes of the given type.
3953
+
Populate the array A with random values.
3962
3954
3963
3955
.. function:: rand(r, [dims...])
3964
3956
3965
3957
Pick a random element or array of random elements from range ``r`` (for example, ``1:n`` or ``0:2:10``).
3966
3958
3967
-
.. function:: randbool([dims...])
3959
+
.. function:: randbool([rng], [dims...])
3968
3960
3969
-
Generate a random boolean value. Optionally, generate an array of random boolean values.
3961
+
Generate a random boolean value. Optionally, generate a ``BitArray`` of random boolean values.
3970
3962
3971
-
.. function:: randn([rng], dims or [dims...])
3963
+
.. function:: randn([rng], [dims...])
3972
3964
3973
3965
Generate a normally-distributed random number with mean 0 and standard deviation 1. Optionally generate an array of normally-distributed random numbers.
0 commit comments