Skip to main content

Module rand

Module rand 

Source
Expand description

Random value generation and randomized truncation helpers.

These helpers use the thread-local generator for strings, indexes, shuffles, durations, and event identifiers. Range arguments use half-open semantics.

Re-exportsยง

use std::iter::repeat_with; ๐Ÿ”’
use std::ops::Range; ๐Ÿ”’
use std::time::Duration; ๐Ÿ”’
use std::time::SystemTime; ๐Ÿ”’
use arrayvec::ArrayString; ๐Ÿ”’
use rand::RngExt; ๐Ÿ”’
use rand::rng; ๐Ÿ”’
use rand::seq::SliceRandom; ๐Ÿ”’
use ruma::OwnedEventId; ๐Ÿ”’

Functionsยง

event_id
Generates a Matrix event identifier from 32 random bytes.
index
Chooses a uniformly random index below len.
secs
Generates a Duration with a random whole-second length.
shuffle
Randomly permutes a slice in place.
string
Generates an alphanumeric ASCII string of the requested byte length.
string_array
Generates an alphanumeric ASCII string that fills a fixed-capacity array.
string_from
Generates a string of length characters sampled from charset.
time_from_now_secs
Adds a random whole-second offset to the current SystemTime.
truncate_str
Borrows a prefix ending at a randomly selected character count.
truncate_string
Truncates an owned string at a randomly selected character count.