new_short_id
A short id of len characters drawn from an Alphabet with the operating system’s random
source, every character equally likely.
Needs the random-entropy feature. Bytes that would favor some characters (256 is rarely a
multiple of the alphabet size) are discarded, not folded with a modulo. The result carries
len × log2(size) bits of randomness: 21 characters of url_safe give
126 bits, as much as a UUID.
Import
Section titled “Import”Cargo feature id (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
alphabet | &Alphabet | The characters to draw from. |
len | usize | The number of characters. |
Returns
Section titled “Returns”Result<String, EntropyError> — A string of len characters.
Errors
Section titled “Errors”Returns an EntropyError when the operating system cannot provide random bytes.
