Skip to main content

SampleRange

Trait SampleRange 

Source
pub trait SampleRange {
    type Output;

    // Required method
    fn sample(self) -> Self::Output;
}
Available on crate features rand-expand and rand only.
Expand description

可从区间采样的类型。

  • 整数区间采用拒绝采样实现无偏取模,不引入模偏差;
  • 浮点区间按 start + random::<T>() * (end - start) 缩放。

§Feature Requirement

需要启用 "rand-expand" 特性。

§Examples

use lib_unknown::rand::random_range;

let v = random_range(0..10u32);
assert!(v < 10);

Required Associated Types§

Source

type Output

采样输出类型(与区间元素类型一致)。

Required Methods§

Source

fn sample(self) -> Self::Output

执行一次采样(约束违反时 panic,见 random_range)。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SampleRange for Range<f32>

Source§

type Output = f32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> f32

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<f64>

Source§

type Output = f64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> f64

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<i8>

Source§

type Output = i8

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i8

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<i16>

Source§

type Output = i16

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i16

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<i32>

Source§

type Output = i32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i32

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<i64>

Source§

type Output = i64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i64

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<isize>

Source§

type Output = isize

Available on crate feature rand-expand only.
Source§

fn sample(self) -> isize

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<u8>

Source§

type Output = u8

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u8

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<u16>

Source§

type Output = u16

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u16

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<u32>

Source§

type Output = u32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u32

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<u64>

Source§

type Output = u64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u64

Available on crate feature rand-expand only.
Source§

impl SampleRange for Range<usize>

Source§

type Output = usize

Available on crate feature rand-expand only.
Source§

fn sample(self) -> usize

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<f32>

Source§

type Output = f32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> f32

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<f64>

Source§

type Output = f64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> f64

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<i8>

Source§

type Output = i8

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i8

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<i16>

Source§

type Output = i16

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i16

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<i32>

Source§

type Output = i32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i32

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<i64>

Source§

type Output = i64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> i64

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<isize>

Source§

type Output = isize

Available on crate feature rand-expand only.
Source§

fn sample(self) -> isize

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<u8>

Source§

type Output = u8

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u8

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<u16>

Source§

type Output = u16

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u16

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<u32>

Source§

type Output = u32

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u32

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<u64>

Source§

type Output = u64

Available on crate feature rand-expand only.
Source§

fn sample(self) -> u64

Available on crate feature rand-expand only.
Source§

impl SampleRange for RangeInclusive<usize>

Source§

type Output = usize

Available on crate feature rand-expand only.
Source§

fn sample(self) -> usize

Available on crate feature rand-expand only.

Implementors§