randstring

..  randstring([rng,] len=8)

Create a random ASCII string of length ``len``, consisting of upper- and
lower-case letters and the digits 0-9. The optional ``rng`` argument
specifies a random number generator, see :ref:`Random Numbers <random-numbers>`.

Examples

The randstring function in Julia generates a random ASCII string of a specified length. It consists of upper- and lower-case letters and the digits 0-9. The function also accepts an optional random number generator argument.

julia> randstring(10)
"3w8H7kXu2h"

julia> randstring(5)
"y9V7Z"

julia> randstring(12)
"yW7jFy2o1j9A"

In the above examples, randstring generates random strings of lengths 10, 5, and 12, respectively.

You can also provide a random number generator as an optional argument:

julia> rng = Random.MersenneTwister(1234);  # Create a specific random number generator
julia> randstring(rng, 8)
"MIuYaP0v"

julia> randstring(rng, 6)
"T9B0Ez"

julia> randstring(rng, 9)
"v8vH2A2DN"

In this example, the rng argument is passed to randstring to use a specific random number generator (MersenneTwister in this case).

Please note that the exact output of randstring will vary each time you run it due to its random nature.

See Also

ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,

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: