Skip to main content

Random

Trait Random 

Source
pub trait Random {
    // Required method
    fn random() -> Self;
}
Available on crate features rand-expand and rand only.
Expand description

可随机生成的类型。

熵源取自 next。各实现的取值语义:

  • 整数:取 next() 输出并截断为目标位宽(as 转换);
  • bool:取最低位;
  • 浮点(f32 / f64):[0, 1) 区间内均匀分布。

§Feature Requirement

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

§Examples

use lib_unknown::rand::{Random, random};

let v: u64 = random();
let _ = v;

Required Methods§

Source

fn random() -> Self

生成一个该类型的随机值(语义见 trait 级文档)。

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Random for bool

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for f32

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for f64

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for i8

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for i16

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for i32

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for i64

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for isize

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for u8

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for u16

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for u32

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for u64

Source§

fn random() -> Self

Available on crate feature rand-expand only.
Source§

impl Random for usize

Source§

fn random() -> Self

Available on crate feature rand-expand only.

Implementors§