z_ids (zotonic_core v1.0.0-rc.10)

Server supplying random strings and unique ids

Link to this section Summary

Functions

Equivalent to id(?ID_LENGTH).

Generate a random key consisting of numbers and upper and lower case characters.

Equivalent to identifier(?OPTID_LENGTH).
Get a random identifier of a certain length, consisting of lower case characters only.
Equivalent to number(1000000000).
Return a random integer less than or equal to Max. Max defaults to a large number smaller than MaxInt.
Return N random bytes. This falls back to the pseudo random version of rand_uniform if strong_rand_bytes fails.
Get a random identifier of the specified length, consisting of characters from the specified set: - 'az' [a-z] : lower case characters only. - 'az09' [a-z0-9] : lower case characters and numbers only. - 'azAZ09' [a-zA-Z0-9]: lower and upper case characters and numbers.
Get the key for signing requests stored in the user agent.
Get the key for less secure signing of data (without nonce).

Return an unique id to be used in javascript or html. No randomness, just unique for the current runtime system instance.

Link to this section Types

-type charset() :: az | az09 | azAZ09.

Link to this section Functions

-spec id() -> binary().
Equivalent to id(?ID_LENGTH).
-spec id(Length :: integer()) -> binary().

Generate a random key consisting of numbers and upper and lower case characters.

The version with the default Length can be used for session ids: the result is sufficiently random and sufficiently unique.
-spec identifier() -> binary().
Equivalent to identifier(?OPTID_LENGTH).
Link to this function

identifier(Length)

-spec identifier(Length :: integer()) -> binary().
Get a random identifier of a certain length, consisting of lower case characters only.
-spec number() -> integer().
Equivalent to number(1000000000).
-spec number(Max :: integer()) -> integer().
Return a random integer less than or equal to Max. Max defaults to a large number smaller than MaxInt.
-spec optid(undefined | false | binary()) -> binary().
-spec rand_bytes(integer()) -> binary().
Return N random bytes. This falls back to the pseudo random version of rand_uniform if strong_rand_bytes fails.
Link to this function

random_id(_, Length)

-spec random_id(charset(), Length :: integer()) -> binary().
Get a random identifier of the specified length, consisting of characters from the specified set: - 'az' [a-z] : lower case characters only. - 'az09' [a-z0-9] : lower case characters and numbers only. - 'azAZ09' [a-zA-Z0-9]: lower and upper case characters and numbers.
Link to this function

sign_key(Context)

-spec sign_key(Context :: term()) -> binary().
Get the key for signing requests stored in the user agent.
Link to this function

sign_key_simple(Context)

-spec sign_key_simple(Context :: term()) -> binary().
Get the key for less secure signing of data (without nonce).
-spec unique() -> binary().

Return an unique id to be used in javascript or html. No randomness, just unique for the current runtime system instance.

Returns a binary of unspecified length starting with the character $t followed by a number of digits, example: <<"t123456">>. Note that ids are not unique among connected nodes or after a restart.