From 7c566b1564cc9ee8cc7060329147b444f5113de1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 29 Jun 2021 18:37:40 -0400 Subject: [PATCH] fix #41346, update Random docs for Xoshiro256++ (#41353) --- doc/src/manual/documentation.md | 3 +-- stdlib/Random/docs/src/index.md | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/doc/src/manual/documentation.md b/doc/src/manual/documentation.md index 1bfbc6f36eab6..77a3e78dfd970 100644 --- a/doc/src/manual/documentation.md +++ b/doc/src/manual/documentation.md @@ -128,8 +128,7 @@ As in the example above, we recommend following some simple conventions when wri Calling `rand` and other RNG-related functions should be avoided in doctests since they will not produce consistent outputs during different Julia sessions. If you would like to show some random number generation related functionality, one option is to explicitly construct and seed your own - [`MersenneTwister`](@ref) (or other pseudorandom number generator) and pass it to the functions you are - doctesting. + RNG object (see [`Random`](@ref Random-Numbers)) and pass it to the functions you are doctesting. Operating system word size ([`Int32`](@ref) or [`Int64`](@ref)) as well as path separator differences (`/` or `\`) will also affect the reproducibility of some doctests. diff --git a/stdlib/Random/docs/src/index.md b/stdlib/Random/docs/src/index.md index facb18bbdd8d5..f5508781ef27b 100644 --- a/stdlib/Random/docs/src/index.md +++ b/stdlib/Random/docs/src/index.md @@ -4,20 +4,22 @@ DocTestSetup = :(using Random) ``` -Random number generation in Julia uses the [Mersenne Twister library](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT) -via `MersenneTwister` objects. Julia has a global RNG, which is used by default. Other RNG types -can be plugged in by inheriting the `AbstractRNG` type; they can then be used to have multiple -streams of random numbers. Besides `MersenneTwister`, Julia also provides the `RandomDevice` RNG -type, which is a wrapper over the OS provided entropy. - -Most functions related to random generation accept an optional `AbstractRNG` object as first argument, -which defaults to the global one if not provided. Moreover, some of them accept optionally -dimension specifications `dims...` (which can be given as a tuple) to generate arrays of random -values. In a multi-threaded program, you should generally use different RNG objects from different threads -in order to be thread-safe. However, the default global RNG is thread-safe as of Julia 1.3 (because -it internally corresponds to a per-thread RNG). - -A `MersenneTwister` or `RandomDevice` RNG can generate uniformly random numbers of the following types: +Random number generation in Julia uses the [Xoshiro256++](https://prng.di.unimi.it/) algorithm +by default, with per-`Task` state. +Other RNG types can be plugged in by inheriting the `AbstractRNG` type; they can then be used to +obtain multiple streams of random numbers. +Besides the default `TaskLocalRNG` type, the `Random` package also provides `MersenneTwister`, +`RandomDevice` (which exposes OS-provided entropy), and `Xoshiro` (for explicitly-managed +Xoshiro256++ streams). + +Most functions related to random generation accept an optional `AbstractRNG` object as first argument. +Some also accept dimension specifications `dims...` (which can also be given as a tuple) to generate +arrays of random values. +In a multi-threaded program, you should generally use different RNG objects from different threads +or tasks in order to be thread-safe. However, the default RNG is thread-safe as of Julia 1.3 +(using a per-thread RNG up to version 1.6, and per-task thereafter). + +The provided RNGs can generate uniform random numbers of the following types: [`Float16`](@ref), [`Float32`](@ref), [`Float64`](@ref), [`BigFloat`](@ref), [`Bool`](@ref), [`Int8`](@ref), [`UInt8`](@ref), [`Int16`](@ref), [`UInt16`](@ref), [`Int32`](@ref), [`UInt32`](@ref), [`Int64`](@ref), [`UInt64`](@ref), [`Int128`](@ref), [`UInt128`](@ref), @@ -67,6 +69,8 @@ Random.shuffle! ```@docs Random.seed! Random.AbstractRNG +Random.TaskLocalRNG +Random.Xoshiro Random.MersenneTwister Random.RandomDevice ```