Skip to content

Commit 60f54ac

Browse files
committed
add rand([rng], ::String, [chars], n=8)
1 parent 0d91a23 commit 60f54ac

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

base/random.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,18 +1416,33 @@ let b = UInt8['0':'9';'A':'Z';'a':'z']
14161416
randstring(r::AbstractRNG, n::Int) = randstring(r, b, n)
14171417
randstring(chars::AbstractArray{<:Union{UInt8,Char}}=b, n::Int=8) = randstring(GLOBAL_RNG, chars, n)
14181418
randstring(n::Int) = randstring(GLOBAL_RNG, b, n)
1419+
1420+
rand(rng::AbstractRNG, ::Type{String}, chars::AbstractArray{<:Union{UInt8,Char}}=b, n::Int=8) =
1421+
randstring(rng, chars, n)
1422+
rand(rng::AbstractRNG, ::Type{String}, n::Int) = randstring(rng, b, n)
1423+
rand(::Type{String}, chars::AbstractArray{<:Union{UInt8,Char}}=b, n::Int=8) =
1424+
randstring(GLOBAL_RNG, chars, n)
1425+
rand(::Type{String}, n::Int) = randstring(GLOBAL_RNG, b, n)
14191426
end
14201427

14211428
"""
14221429
randstring([rng=GLOBAL_RNG], [chars::AbstractArray{<:Union{UInt8,Char}}], [len=8])
14231430
1424-
Create a random ASCII string of length `len`, consisting of characters
1431+
Create a random string of length `len`, consisting of characters
14251432
from `chars` if specified, and of upper- and lower-case letters and
14261433
the digits 0-9 otherwise. The optional `rng` argument specifies a
14271434
random number generator, see [Random Numbers](@ref).
14281435
"""
14291436
randstring
14301437

1438+
"""
1439+
rand([rng=GLOBAL_RNG], ::Type{String}, [chars::AbstractArray{<:Union{UInt8,Char}}], [len=8])
1440+
1441+
Create a random string of length `len`, consisting of characters
1442+
from `chars` if specified, and of upper- and lower-case letters and
1443+
the digits 0-9 otherwise. Equivalent to [`randstring`](@ref)`(rng, chars, len)`.
1444+
"""
1445+
14311446
# Fill S (resized as needed) with a random subsequence of A, where
14321447
# each element of A is included in S with independent probability p.
14331448
# (Note that this is different from the problem of finding a random

0 commit comments

Comments
 (0)