Vely logo install
examples
documentation

Vely 15.2.0 released on Jan 18, 2023
Articles updated Jan 17, 2023

random-string


Issues with this documentation page? Report here.

Purpose:


Obtain a random string.

Syntax:



random-string to [ define ] <random string> \
    [ length <string length> ] \
    [ number | binary ]


Description:


random-string obtains a random string of length <string length>. If "length" clause is omitted, the length is 20 by default. You can create <random string> with "define" clause. <random string> is allocated memory.

If "number" clause is used, then the resulting string is composed of digits only ("0" through "9").

If "binary" clause is used, then the resulting string is binary, i.e. each byte can have an unsigned value of 0-255.

By default, if neither "number" or "binary" is used, the resulting string is alphanumeric, i.e. digits ("0" through "9") and alphabet letters ("a"-"z" and "A"-"Z") are used only.

Random generator is based on the Linux random() generator seeded by local process properties such as its PID and time. A single process is seeded once, and thus any number of requests served by the same process will use a subset of the process' random sequence. Due to joint entropy, each result given to any request is random, not just within a single request, but among any number of different requests.

Note that in any case, the random string is null-terminated.

Examples:


Get a 100-digit long random value (as an alphanumeric string):

random-string to define str length 100
pf-out "%s\n", str

Get a random number of length 10 in string representation:

random-string to define str length 10 number
pf-out "%s\n", str

Get a random binary value that is 8 bytes in length - this value may contain null characters (i.e. it will contain bytes with values ranging from 0 to 255) and will also be null-terminated regardless:

random-string to define str length 8 binary


See also:


Encryption ( decrypt-data   derive-key   encrypt-data   hash-string   random-crypto   random-string  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Vely elephant logo (c) 2022 DaSoftver LLC. This web page is licensed under CC-BY-SA-4.0.