@@ -297,13 +297,16 @@ randperm(r::AbstractRNG, n::T) where {T <: Integer} = randperm!(r, Vector{T}(und
297
297
randperm (n:: Integer ) = randperm (default_rng (), n)
298
298
299
299
"""
300
- randperm!([rng=default_rng(),] A::Array {<:Integer})
300
+ randperm!([rng=default_rng(),] A::AbstractArray {<:Integer})
301
301
302
302
Construct in `A` a random permutation of length `length(A)`. The
303
303
optional `rng` argument specifies a random number generator (see
304
304
[Random Numbers](@ref)). To randomly permute an arbitrary vector, see
305
305
[`shuffle`](@ref) or [`shuffle!`](@ref).
306
306
307
+ !!! compat "Julia 1.13"
308
+ `A isa Array` was required prior to Julia v1.13.
309
+
307
310
# Examples
308
311
```jldoctest
309
312
julia> randperm!(Xoshiro(123), Vector{Int}(undef, 4))
@@ -314,8 +317,9 @@ julia> randperm!(Xoshiro(123), Vector{Int}(undef, 4))
314
317
3
315
318
```
316
319
"""
317
- function randperm! (r:: AbstractRNG , a:: Array {<:Integer} )
320
+ function randperm! (r:: AbstractRNG , a:: AbstractArray {<:Integer} )
318
321
# keep it consistent with `shuffle!` and `randcycle!` if possible
322
+ Base. require_one_based_indexing (a)
319
323
n = length (a)
320
324
@assert n <= Int64 (2 )^ 52
321
325
n == 0 && return a
@@ -332,7 +336,7 @@ function randperm!(r::AbstractRNG, a::Array{<:Integer})
332
336
return a
333
337
end
334
338
335
- randperm! (a:: Array {<:Integer} ) = randperm! (default_rng (), a)
339
+ randperm! (a:: AbstractArray {<:Integer} ) = randperm! (default_rng (), a)
336
340
337
341
338
342
# # randcycle & randcycle!
@@ -370,7 +374,7 @@ randcycle(r::AbstractRNG, n::T) where {T <: Integer} = randcycle!(r, Vector{T}(u
370
374
randcycle (n:: Integer ) = randcycle (default_rng (), n)
371
375
372
376
"""
373
- randcycle!([rng=default_rng(),] A::Array {<:Integer})
377
+ randcycle!([rng=default_rng(),] A::AbstractArray {<:Integer})
374
378
375
379
Construct in `A` a random cyclic permutation of length `n = length(A)`.
376
380
The optional `rng` argument specifies a random number generator, see
@@ -382,6 +386,9 @@ which are sampled uniformly. If `A` is empty, `randcycle!` leaves it unchanged.
382
386
383
387
[`randcycle`](@ref) is a variant of this function that allocates a new vector.
384
388
389
+ !!! compat "Julia 1.13"
390
+ `A isa Array` was required prior to Julia v1.13.
391
+
385
392
# Examples
386
393
```jldoctest
387
394
julia> randcycle!(Xoshiro(123), Vector{Int}(undef, 6))
@@ -394,8 +401,9 @@ julia> randcycle!(Xoshiro(123), Vector{Int}(undef, 6))
394
401
1
395
402
```
396
403
"""
397
- function randcycle! (r:: AbstractRNG , a:: Array {<:Integer} )
404
+ function randcycle! (r:: AbstractRNG , a:: AbstractArray {<:Integer} )
398
405
# keep it consistent with `shuffle!` and `randperm!` if possible
406
+ Base. require_one_based_indexing (a)
399
407
n = length (a)
400
408
@assert n <= Int64 (2 )^ 52
401
409
n == 0 && return a
@@ -411,4 +419,4 @@ function randcycle!(r::AbstractRNG, a::Array{<:Integer})
411
419
return a
412
420
end
413
421
414
- randcycle! (a:: Array {<:Integer} ) = randcycle! (default_rng (), a)
422
+ randcycle! (a:: AbstractArray {<:Integer} ) = randcycle! (default_rng (), a)
0 commit comments