RandomDevice

RandomDevice()

Create a RandomDevice RNG object. Two such objects will always generate different streams of random numbers.

Examples

  1. Create a RandomDevice object:

    julia> rng = RandomDevice()
    RandomDevice()
    
    julia> rand(rng, 3)
    3-element Array{Float64,1}:
    0.8001107062114954
    0.4821127743457391
    0.6071435902237073

    This example creates a RandomDevice object named rng. You can then use the rng object to generate random numbers using the rand function.

  2. Generate random integers using RandomDevice:

    julia> rng = RandomDevice()
    RandomDevice()
    
    julia> rand(rng, 1:10, 5)
    5-element Array{Int64,1}:
    5
    8
    3
    3
    2

    Here, the rand function is used with the RandomDevice object rng to generate an array of 5 random integers between 1 and 10 (inclusive).

  3. Generate a random permutation using RandomDevice:

    julia> rng = RandomDevice()
    RandomDevice()
    
    julia> randperm(rng, 5)
    5-element Array{Int64,1}:
    2
    5
    3
    1
    4

    In this example, the randperm function is used with the RandomDevice object rng to generate a random permutation of the numbers from 1 to 5.

Common mistake example:

julia> rng = RandomDevice
ERROR: MethodError: no method matching RandomDevice()

In this example, the mistake made is not calling the RandomDevice constructor with parentheses. It is important to use RandomDevice() to create a RandomDevice object, not just RandomDevice.

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: