MersenneTwister

MersenneTwister([seed])

Create a MersenneTwister RNG object. Different RNG objects can have their own seeds, which may be useful for generating different streams of random numbers.

Examples

  1. Create a MersenneTwister RNG object with a default seed:

    julia> rng = MersenneTwister()
    MersenneTwister(123456789)

    This example creates a MersenneTwister random number generator object with the default seed value of 123456789.

  2. Create a MersenneTwister RNG object with a specific seed:

    julia> rng = MersenneTwister(987654321)
    MersenneTwister(987654321)

    Here, a MersenneTwister RNG object is created with a seed value of 987654321.

  3. Generate random numbers using the MersenneTwister RNG object:

    julia> rng = MersenneTwister(1234)
    MersenneTwister(1234)
    
    julia> rand(rng, 5)
    5-element Array{Float64,1}:
    0.590844
    0.766376
    0.566237
    0.256434
    0.672781

    In this example, the rand function is used with the MersenneTwister RNG object to generate an array of 5 random numbers.

Common mistake example:

julia> rng = MersenneTwister(-1)
ERROR: DomainError: The seed provided (-1) is outside the valid seed range for MersenneTwister.

Here, an invalid seed value of -1 is provided, which results in a DomainError since the seed must be within the valid range. Ensure that the seed value is a non-negative integer when using MersenneTwister.

See Also

bitrand, MersenneTwister, rand, randcycle, randexp, randexp!, randjump, randn, randn!, RandomDevice, randperm, randsubseq, randsubseq!, shuffle, srand,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: