diff --git a/base/bitarray.jl b/base/bitarray.jl index 6900d54318320..c27646a7fcec0 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -239,10 +239,10 @@ function bitarray_rand_fill!(B::BitArray) end Bc = B.chunks for i = 1 : length(Bc) - 1 - Bc[i] = randi(Uint64) + Bc[i] = rand(Uint64) end msk = @_msk_end length(B) - Bc[end] = msk & randi(Uint64) + Bc[end] = msk & rand(Uint64) return B end diff --git a/base/combinatorics.jl b/base/combinatorics.jl index b08c3536449b4..13c7c6d9d3335 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -64,7 +64,7 @@ pascal(n) = [binomial(i+j-2,i-1) for i=1:n,j=1:n] function shuffle!(a::AbstractVector) for i = length(a):-1:2 - j = randi(i) + j = rand(1:i) a[i], a[j] = a[j], a[i] end return a @@ -76,7 +76,7 @@ function randperm(n::Integer) a = Array(typeof(n), n) a[1] = 1 for i = 2:n - j = randi(i) + j = rand(1:i) a[i] = a[j] a[j] = i end @@ -87,7 +87,7 @@ function randcycle(n::Integer) a = Array(typeof(n), n) a[1] = 1 for i = 2:n - j = randi(i-1) + j = rand(1:i-1) a[i] = a[j] a[j] = i end diff --git a/base/exports.jl b/base/exports.jl index ba587607a8a6a..11306836ab393 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -946,18 +946,12 @@ export randn, RNG, # deprecated stuff - randbeta!, randbeta, - randchi2!, randchi2, - randexp!, randexp, - randg!, randg, randg2, - randi!, randi, - randival!, randival, # statistics diff --git a/base/file.jl b/base/file.jl index c4f0c36b92558..8d8c4233cad7a 100644 --- a/base/file.jl +++ b/base/file.jl @@ -142,7 +142,7 @@ end end @windows_only function mktempdir() - seed = randi(Uint32) + seed = rand(Uint32) while true filename = GetTempFileName(seed) ret = ccall(:_mkdir, Int32, (Ptr{Uint8},), filename) diff --git a/base/random.jl b/base/random.jl index 0e6af615801ed..11d7b227dfaee 100644 --- a/base/random.jl +++ b/base/random.jl @@ -5,11 +5,6 @@ using Base.LibRandom export librandom_init, srand, rand, rand!, randn, randn!, - randi, randi!, randival, randival!, - randg, randg!, - randexp, randexp!, - randchi2, randchi2!, - randbeta, randbeta!, randbool, randbool!, AbstractRNG, RNG, MersenneTwister @@ -134,15 +129,13 @@ rand(::Type{Int32}) = int32(rand(Uint32)) & typemax(Int32) rand(::Type{Int64}) = int64(rand(Uint64)) & typemax(Int64) rand(::Type{Int128}) = int128(rand(Uint128)) & typemax(Int128) -rand() = rand(Int) - # random integer from lo to hi inclusive function rand{T<:Integer}(r::Range1{T}) lo = r[1] hi = r[end] m = typemax(T) - s = randi(T) + s = rand(T) if (hi-lo == m) return s + lo end @@ -154,7 +147,7 @@ function rand{T<:Integer}(r::Range1{T}) # note: m>=0 && r>=0 lim = m - rem(rem(m,r)+1, r) while s > lim - s = randi(T) + s = rand(T) end return rem(s,r) + lo end diff --git a/base/sparse.jl b/base/sparse.jl index 854248c921032..3d2930fee9e14 100644 --- a/base/sparse.jl +++ b/base/sparse.jl @@ -404,8 +404,8 @@ end function sprand(m::Integer, n::Integer, density::FloatingPoint, rng::Function, v) numnz = int(m*n*density) - I = randival!(1, m, Array(Int, numnz)) - J = randival!(1, n, Array(Int, numnz)) + I = rand!(1:m, Array(Int, numnz)) + J = rand!(1:n, Array(Int, numnz)) S = sparse(I, J, v, m, n) if !isbool(v) S.nzval = rng(nnz(S)) diff --git a/test/arrayperf.jl b/test/arrayperf.jl index a6ecdc348b2fa..10d1a849a5f7d 100644 --- a/test/arrayperf.jl +++ b/test/arrayperf.jl @@ -38,12 +38,12 @@ if run_ref for n_dims in 1:10 sz = ntuple(n_dims,i->lensmall) A = randn(sz) - ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (rand(1:sz[i])))) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) B = A[ind...] end end @@ -51,12 +51,12 @@ if run_ref for n_dims in 1:length(lenbig) sz = ntuple(n_dims,i->lenbig[n_dims]) A = randn(sz) - ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (rand(1:sz[i])))) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) B = A[ind...] end end @@ -67,12 +67,12 @@ if run_ref for n_dims in 1:10 sz = ntuple(n_dims,i->lensmall) A = randn(sz) - ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) B = A[ind...] end end @@ -80,12 +80,12 @@ if run_ref for n_dims in 1:length(lenbig) sz = ntuple(n_dims,i->lenbig[n_dims]) A = randn(sz) - ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) B = A[ind...] end end @@ -95,7 +95,7 @@ if run_ref println("Random operations:") println("Small arrays:") function randind(len) - i = randi(6) + i = rand(1:6) indchoices = {1:len,1:iceil(len/2),1:iceil(3*len/4),2:2:len,1:iceil(len/2):len,len:-1:1} return indchoices[i] end @@ -159,13 +159,13 @@ if run_assign for n_dims in 1:10 sz = ntuple(n_dims,i->lensmall) B = zeros(sz) - ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (rand(1:sz[i])))) A = randn(map(length,ind)) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) # A = randn(map(length,ind)) B[ind...] = A end @@ -174,13 +174,13 @@ if run_assign for n_dims in 1:length(lenbig) sz = ntuple(n_dims,i->lenbig[n_dims]) B = zeros(sz) - ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i <= ceil(n_dims/2)) ? (1:sz[i]) : (rand(1:sz[i])))) A = randn(map(length,ind)) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r -# ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) +# ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) # A = randn(map(length,ind)) B[ind...] = A end @@ -192,13 +192,13 @@ if run_assign for n_dims in 1:10 sz = ntuple(n_dims,i->lensmall) B = zeros(sz) - ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) A = randn(map(length,ind)) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) # A = randn(map(length,ind)) B[ind...] = A end @@ -207,13 +207,13 @@ if run_assign for n_dims in 1:length(lenbig) sz = ntuple(n_dims,i->lenbig[n_dims]) B = zeros(sz) - ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + ind = ntuple(n_dims,i -> ((i > n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) A = randn(map(length,ind)) n_el = prod(map(length,ind)) n_r = iceil(n_evals/n_el) print(n_dims, " dimensions (", n_r, " repeats, ", n_r*n_el, " operations): ") @time for i = 1:n_r - # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (randi(sz[i])))) + # ind = ntuple(n_dims,i -> ((i <= n_dims/2) ? (1:sz[i]) : (rand(1:sz[i])))) # A = randn(map(length,ind)) B[ind...] = A end @@ -224,7 +224,7 @@ if run_assign println("Random operations:") println("Small arrays:") function randind(len) - i = randi(6) + i = rand(1:6) indchoices = {1:len,1:iceil(len/2),1:iceil(3*len/4),2:2:len,1:iceil(len/2):len,len:-1:1} return indchoices[i] end diff --git a/test/bitarray.jl b/test/bitarray.jl index c7349c3b4ea95..875869caa0e5c 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -34,7 +34,7 @@ s4 = 4 b1 = randbool(n1, n2) @test isequal(bitpack(bitunpack(b1)), b1) -i1 = randi(2, n1, n2) - 1 +i1 = rand(1:2, n1, n2) - 1 @test isequal(bitunpack(bitpack(i1)), i1) timesofar("conversions") @@ -56,8 +56,8 @@ timesofar("utils") ## Indexing ## b1 = randbool(n1, n2) -m1 = randi(n1) -m2 = randi(n2) +m1 = rand(1:n1) +m2 = rand(1:n2) b2 = randbool(m1, m2) @check_bit_operation copy_to BitMatrix (b1, b2) @check_bit_operation ref BitMatrix (b1, 1:m1, m2:n2) @@ -68,8 +68,8 @@ b2 = randbool(m1, m2) b2 = randbool(m1) @check_bit_operation assign BitMatrix (b1, b2, 1:m1, m2) -for p1 = [randi(v1) 1 63 64 65 191 192 193] - for p2 = [randi(v1) 1 63 64 65 191 192 193] +for p1 = [rand(1:v1) 1 63 64 65 191 192 193] + for p2 = [rand(1:v1) 1 63 64 65 191 192 193] for n = 0 : min(v1 - p1 + 1, v1 - p2 + 1) b1 = randbool(v1) b2 = randbool(v1) @@ -145,7 +145,7 @@ end b1 = BitArray() i1 = bitunpack(b1) for m = 1 : v1 - j = randi(m) + j = rand(1:m) x = randbool() insert!(b1, j, x) insert!(i1, j, x) @@ -155,7 +155,7 @@ end b1 = randbool(v1) i1 = bitunpack(b1) for j in [63, 64, 65, 127, 128, 129, 191, 192, 193] - x = randi(2) - 1 + x = rand(1:2) - 1 insert!(b1, j, x) insert!(i1, j, x) @test isequal(bitunpack(b1), i1) @@ -164,7 +164,7 @@ end b1 = randbool(v1) i1 = bitunpack(b1) for m = v1 : -1 : 1 - j = randi(m) + j = rand(1:m) delete!(b1, j) delete!(i1, j) @test isequal(bitunpack(b1), i1) @@ -248,7 +248,7 @@ b2 = randbool(n1, n1) @check_bit_operation (\) Matrix{Float64} (b1, b1) b1 = randbool(n1, n2) -b2 = randi(10, n1, n2) +b2 = rand(1:10, n1, n2) @check_bit_operation (&) Matrix{Int} (b1, b2) @check_bit_operation (|) Matrix{Int} (b1, b2) @check_bit_operation ($) Matrix{Int} (b1, b2) @@ -291,7 +291,7 @@ timesofar("binary comparison") b1 = randbool(s1, s2, s3, s4) for d = 1 : 4 - j = randi(size(b1, d)) + j = rand(1:size(b1, d)) #for j = 1 : size(b1, d) @check_bit_operation slicedim BitArray{4} (b1, d, j) #end @@ -309,7 +309,7 @@ for m = 0 : v1 end b1 = randbool(v1) -for m = [randi(v1)-1 0 1 63 64 65 191 192 193 v1-1] +for m = [rand(1:v1)-1 0 1 63 64 65 191 192 193 v1-1] @test isequal(b1 << m, [ b1[m+1:end]; falses(m) ]) @test isequal(b1 >>> m, [ falses(m); b1[1:end-m] ]) @test isequal(rotl(b1, m), [ b1[m+1:end]; b1[1:m] ]) diff --git a/test/combinatorics.jl b/test/combinatorics.jl index 57b167d27ec1d..a047e973b638c 100644 --- a/test/combinatorics.jl +++ b/test/combinatorics.jl @@ -44,7 +44,7 @@ for i = -5:.5:4 @test search_sorted_last_r(rg_r, i) == search_sorted_last_r(rgv_r, i) end -a = randi(10000, 1000) +a = rand(1:10000, 1000) # insertion_sort for _sort in [insertionsort, mergesort, timsort] diff --git a/test/corelib.jl b/test/corelib.jl index 61f163035fd68..3627f6e6785e1 100644 --- a/test/corelib.jl +++ b/test/corelib.jl @@ -148,7 +148,7 @@ end @test !isequal({1 => 1}, {2 => 1}) # Generate some data to populate dicts to be compared -data_in = [ (randi(1000), randstring(2)) for _ in 1:1001 ] +data_in = [ (rand(1:1000), randstring(2)) for _ in 1:1001 ] # Populate the first dict d1 = Dict{Int, String}(length(data_in)) @@ -158,7 +158,7 @@ end data_in = pairs(d1) # shuffle the data for i in 1:length(data_in) - j = randi(length(data_in)) + j = rand(1:length(data_in)) data_in[i], data_in[j] = data_in[j], data_in[i] end # Inserting data in different (shuffled) order should result in @@ -172,10 +172,10 @@ end d3 = copy(d2) d4 = copy(d2) # Removing an item gives different dict -delete!(d1, data_in[randi(length(data_in))][1]) +delete!(d1, data_in[rand(1:length(data_in))][1]) @test !isequal(d1, d2) # Changing a value gives different dict -d3[data_in[randi(length(data_in))][1]] = randstring(3) +d3[data_in[rand(1:length(data_in))][1]] = randstring(3) !isequal(d1, d3) # Adding a pair gives different dict d4[1001] = randstring(3) diff --git a/test/gzip.jl b/test/gzip.jl index a7ed2d36712fa..28e4f181df28e 100644 --- a/test/gzip.jl +++ b/test/gzip.jl @@ -176,7 +176,7 @@ let BUFSIZE = 65536 elseif isa(T, Complex128) r = Int64[rand(BUFSIZE)...] + Int64[rand(BUFSIZE)...] * im else - r = b[randi((1,BUFSIZE), BUFSIZE)]; + r = b[rand(1:BUFSIZE, BUFSIZE)]; end # Array file diff --git a/test/linalg.jl b/test/linalg.jl index d707ee8c85f53..ed9a001796ddf 100644 --- a/test/linalg.jl +++ b/test/linalg.jl @@ -180,8 +180,8 @@ B = [2 -2; 3 -5; -4 7] A = ones(Int, 2, 100) B = ones(Int, 100, 3) @test A*B == [100 100 100; 100 100 100] -A = randi(20, 5, 5) - 10 -B = randi(20, 5, 5) - 10 +A = rand(1:20, 5, 5) - 10 +B = rand(1:20, 5, 5) - 10 @test At_mul_B(A, B) == A'*B @test A_mul_Bt(A, B) == A*B' # Preallocated diff --git a/test/perf/perf.jl b/test/perf/perf.jl index 1b2ad28b7de32..aae5097669e5d 100644 --- a/test/perf/perf.jl +++ b/test/perf/perf.jl @@ -23,7 +23,7 @@ fib(n) = n < 2 ? n : fib(n-1) + fib(n-2) function parseintperf(t) local n, m for i=1:t - n = randi(Uint32) + n = rand(Uint32) s = hex(n) m = uint32(parse_hex(s)) end diff --git a/test/zlib.jl b/test/zlib.jl index 12a7e1c6ca97e..8a86a032fc057 100644 --- a/test/zlib.jl +++ b/test/zlib.jl @@ -17,7 +17,7 @@ for i = 1:length(b) end # Random array -r = b[randi((1,256), BUFSIZE)] +r = b[rand(1:256, BUFSIZE)] ######################## # type size tests