Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for random #109

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,26 @@ pub trait ContextRandomExt {
where
R::RngType: Rng;

/// Gets a random sample within the range provided by `range`
/// using the generator associated with the given `RngId`.
/// Note that this will panic if `set_base_random_seed` was not called yet.
fn sample_range<R: RngId + 'static, S, T>(&self, rng_type: R, range: S) -> T
where
R::RngType: Rng,
S: SampleRange<T>,
T: SampleUniform;

/// Gets a random boolean value which is true with probability `p`
/// using the generator associated with the given `RngId`.
/// Note that this will panic if `set_base_random_seed` was not called yet.
fn sample_bool<R: RngId + 'static>(&self, rng_id: R, p: f64) -> bool
where
R::RngType: Rng;

/// Draws a random entry out of the list provided in `weights`
/// with the given weights using the generator associated with the
/// given `RngId`. Note that this will panic if
/// `set_base_random_seed` was not called yet.
fn sample_weighted<R: RngId + 'static, T>(&self, rng_id: R, weights: &[T]) -> usize
where
R::RngType: Rng,
Expand Down