File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -1479,6 +1479,18 @@ from `chars` if specified, and of upper- and lower-case letters and
14791479the digits 0-9 otherwise. The optional `rng` argument specifies a
14801480random number generator, see [Random Numbers](@ref).
14811481
1482+ # Examples
1483+ ```julia-repl
1484+ julia> randstring()
1485+ "c03rgKi1"
1486+
1487+ julia> randstring(MersenneTwister(0), 'a':'z', 6)
1488+ "wijzek"
1489+
1490+ julia> randstring("gcat")
1491+ "tgtcaatc"
1492+ ```
1493+
14821494!!! note
14831495 The collection `chars` can be any collection of characters
14841496 (of type `Char` or `UInt8`)
Original file line number Diff line number Diff line change @@ -539,15 +539,21 @@ let g = Base.Random.GLOBAL_RNG,
539539end
540540
541541# test randstring API
542- let b = [' 0' :' 9' ;' A' :' Z' ;' a' :' z' ],
543- c = ' a' :' z'
542+ let b = [' 0' :' 9' ;' A' :' Z' ;' a' :' z' ]
544543 for rng = [[], [MersenneTwister (0 )]]
545544 @test length (randstring (rng... )) == 8
546545 @test length (randstring (rng... , 20 )) == 20
547546 @test issubset (randstring (rng... ), b)
548- @test issubset (randstring (rng... , c), c)
549- s = randstring (rng... , c, 20 )
550- @test length (s) == 20
551- @test issubset (s, c)
547+ for c = [' a' :' z' , " qwèrtï" , Set (Vector {UInt8} (" gcat" ))],
548+ len = [8 , 20 ]
549+ s = len == 8 ? randstring (rng... , c) : randstring (rng... , c, len)
550+ @test length (s) == len
551+ if eltype (c) == Char
552+ @test issubset (s, c)
553+ else # UInt8
554+ @test issubset (s, map (Char, c))
555+ end
556+ end
552557 end
558+ @test randstring (MersenneTwister (0 )) == randstring (MersenneTwister (0 ), b)
553559end
You can’t perform that action at this time.
0 commit comments