randn

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

Generate a normally-distributed random number with mean 0 and standard deviation 1. Optionally generate an array of normally-distributed random numbers.

Examples

julia> randn(3)
3-element Array{Float64,1}:
 0.886264
 0.951379
 0.189251
julia> randn(1,1)
1x1 Array{Float64,2}:
 -1.10013
julia> randn(10^1)
10-element Array{Float64,1}:
 -0.582411
  0.6569  
 -0.364627
 -0.664332
  2.31059 
 -1.29415 
 -0.324598
  0.866415
  0.199852
  0.350528
julia> randn(10^2)
100-element Array{Float64,1}:
 -0.564138
 -0.290903
  2.34801 
  1.15471 
 -1.96972 
  0.232324
 -0.656563
 -2.44173 
  1.20195 
  0.993468
  0.867964
  0.032737
  0.33407 
  ?       
  0.727052
  0.984324
 -0.627767
  0.252516
  0.382487
 -0.5192  
  0.985186
  0.322768
 -0.506415
 -0.994221
  1.0927  
 -0.343862
  1. Generate a single normally-distributed random number:

    julia> randn()
    0.1950316385222502

    This example generates a single random number from a standard normal distribution.

  2. Generate an array of normally-distributed random numbers:

    julia> randn(3)
    3-element Array{Float64,1}:
    -0.19044704142415453
    -0.4862101494629707
    -0.16060936031308463

    It generates an array of three random numbers from a standard normal distribution.

  3. Specify dimensions for a multidimensional array:

    julia> randn(2, 3)
    2×3 Array{Float64,2}:
    -0.821126  -0.130874  -0.366167
    -0.158623   1.30861    0.334751

    In this example, a 2x3 array of random numbers from a standard normal distribution is generated.

  4. Specify a custom random number generator:
    julia> rng = MersenneTwister(1234);
    julia> randn(rng)
    -0.20497626684002162

    It generates a single random number using a specific random number generator, MersenneTwister in this case.

Common mistake example:

julia> randn(0)
ERROR: ArgumentError: The dims argument must be an integer or a tuple of integers

In this example, an incorrect argument is provided as the dimensions. The dims argument should be an integer or a tuple of integers representing the dimensions of the desired output array.

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: