randexp!([rng], A::Array{Float64,N})

Fill the array A with random numbers following the exponential distribution (with scale 1).


julia> rng = Random.GLOBAL_RNG;  # Optional, use the global random number generator
julia> arr = zeros(3, 3);  # Example array

julia> randexp!(rng, arr)
3×3 Array{Float64,2}:
 0.620358  1.63785   0.0897257
 0.377653  0.0925307  0.729912
 0.268513  0.313195  0.0650422

This example generates random numbers following the exponential distribution and fills the array arr with the generated values. The exponential distribution has a scale parameter of 1.

Note: The rng argument is optional and represents the random number generator used for generating random numbers. If not provided, the global random number generator (Random.GLOBAL_RNG) is used.

Common mistake example:

julia> arr = [1, 2, 3];
julia> randexp!(arr)
ERROR: MethodError: no method matching randexp!(::Array{Int64,1})

In this example, the function randexp! is called with an array of integers. However, the function expects an array of type Array{Float64, N} to fill with the exponential random numbers. Ensure that the array type matches the expected type to avoid such errors.

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: