stringlib::random

Create a random string

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

stringlib::random(<l>, <characters>, options)

Description

stringlib::random() returns a random string of the default length 7.

stringlib::random(l) with a number or a range l returns a random string with length l or length in the given range. When the prefix and/or suffix is longer than the given length, stringlib::random raises an error message.

stringlib::random(characters) with a given list oder set of characters builds the random string of the given characters. When the characters are strings, they are used as single characters, however, the length is exceeded.

stringlib::random(l, characters) is a combination of the both last calls. When both parameters are given, the order is significant.

stringlib defines the lists stringlib::lowerLetters, stringlib::upperLetters, stringlib::digits and stringlib::punctuation with the characters lower letters, upper letters, digits and punctuation.

Examples

Example 1

Create a random string of the default length 7:

stringlib::random()

Create a random string of the length 3:

stringlib::random(3)

Create a random string of the length 2 only of digits:

stringlib::random(2, stringlib::digits)

Create a random string of the length 3 only of digits with prefix "+":

stringlib::random(3, stringlib::digits, Prefix = "+")

Create a random string of the length 5 only of digits with suffix ".0":

stringlib::random(5, stringlib::digits, Suffix = ".0")

Create a random strings of the length 3 to 8 only of letters:

stringlib::random(3..8, stringlib::lowerLetters.
                        stringlib::upperLetters) $ k = 1..5

Create a random string of the length 2 to 8 with letters and casual a punctuation:

stringlib::random(2..8, (stringlib::lowerLetters.
                         stringlib::upperLetters $ 4).
                        stringlib::punctuation) $ k = 1..12

Create a random string of the length 6 to 8 with letters and equivalent punctuation:

stringlib::random(6..8, (stringlib::lowerLetters.
                         stringlib::upperLetters).
                        (stringlib::punctuation $ 2)) $ k = 1..10

Create random names of the length 4 to 6:

stringlib::random(4..6, Name) $ k = 1..12

Create a random password of the length 8 to 10, but without some special characters:

EX := {"\\", "\"", "|", "'", "?", "*", "[", "]"}:
stringlib::random(8..10, Exclude = EX)

Parameters

l

The length of the returned string: a nonnegative integer or a range of nonnegative integers

characters

A list or set of characters

options

Any of the described options

Options

Exclude

Option, specified as Exclude = characters

The returned string does not contain characters given in the set or list characters.

Name

The returned string is a valid MuPAD® object name.

Prefix

Option, specified as Prefix = string

Adds string in front of each random string. The length of the returned string is the given length or the default length including the prefix.

Suffix

Option, specified as Suffix = string

Appends string to each random string. The length of the returned string is the given length or the default length including the suffix.

Return Values

Random string of the given length or the default length including the prefix resp. suffix.

See Also

MuPAD Functions

Was this topic helpful?