rand

rand([rng], [S], [dims...])

Pick a random element or array of random elements from the set of values specified by S; S can be

  • an indexable collection (for example 1:n or ['x','y','z']), or
  • a type: the set of values to pick from is then equivalent to typemin(S):typemax(S) for integers (this is not applicable to BigInt), and to $[0, 1)$ for floating point numbers;

S defaults to Float64.

Examples

julia> rand()
0.41545291085770697
julia> rand(Uint32)
0x96d887ee
julia> rand(3)
3-element Array{Float64,1}:
 0.806615
 0.974651
 0.380263
julia> rand(Int8,2,2)
2x2 Array{Int8,2}:
 -54    107
 -1     -100
 julia> rand(0:10)
 5
 julia> rand(0:2:20, 4)
 4-element Array{Int64,1}:
  2
  10
  20
  6
julia> A = rand(10,5)
10x5 Array{Float64,2}:
 0.694826  0.953467   0.813771   0.852055  0.261838
 0.825119  0.0781648  0.163994   0.890056  0.968585
 0.597318  0.614048   0.953451   0.828575  0.714666
 0.782182  0.158034   0.0773286  0.631305  0.699102
 0.30093   0.701959   0.57233    0.283952  0.43863 
 0.804297  0.580577   0.731646   0.639573  0.243464
 0.564545  0.596057   0.939858   0.133461  0.583886
 0.168195  0.839508   0.128291   0.851288  0.796833
 0.253853  0.95848    0.950334   0.199548  0.163088
 0.722749  0.913511   0.459316   0.108941  0.102196

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: