randexp([rng], [dims...])

Generate a random number according to the exponential distribution with scale 1. Optionally generate an array of such random numbers.


  1. Generate a single random number:

    julia> randexp()

    This example generates a single random number from the exponential distribution with scale 1.

  2. Generate an array of random numbers:

    julia> randexp(3)
    3-element Array{Float64,1}:

    It generates an array of 3 random numbers from the exponential distribution.

  3. Generate random numbers using a specific random number generator:
    julia> rng = MersenneTwister(1234);  # Create a specific RNG
    julia> randexp(rng)

    This example uses a specific random number generator rng to generate a random number from the exponential distribution.

Common mistake example:

julia> randexp(-1)
ERROR: DomainError: The scale parameter of the exponential distribution must be positive

In this example, a negative value is provided as the scale parameter, which results in a domain error. It's important to provide a positive value for the scale parameter to ensure correct behavior of randexp.

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

Checking you are not a robot: