Skip to main content

RandomInt

Trait RandomInt 

Source
pub trait RandomInt
where Self: Sized,
{ type Meta; // Required methods fn randint<S: Into<Shape>>( low: Self::Meta, high: Self::Meta, shape: S, ) -> Result<Self, TensorError> where Self::Meta: SampleUniform, <Self::Meta as SampleUniform>::Sampler: Sync; fn randint_like( &self, low: Self::Meta, high: Self::Meta, ) -> Result<Self, TensorError> where Self::Meta: SampleUniform, <Self::Meta as SampleUniform>::Sampler: Sync; }
Expand description

A trait for generating random integers.

Required Associated Types§

Source

type Meta

Associated type for meta-information or parameters relevant to distributions.

Required Methods§

Source

fn randint<S: Into<Shape>>( low: Self::Meta, high: Self::Meta, shape: S, ) -> Result<Self, TensorError>
where Self::Meta: SampleUniform, <Self::Meta as SampleUniform>::Sampler: Sync,

Create a Tensor with random integers drawn uniformly from the half-open interval [low, high). The distribution is uniform, meaning each integer in the range has an equal probability of being drawn.

§Parameters:

low: Lower bound (inclusive) of the range.

high: Upper bound (exclusive) of the range.

shape: Shape of the output tensor.

§Example:
let a = Tensor::<i32>::randint(0, 100, &[10, 10])?;
Source

fn randint_like( &self, low: Self::Meta, high: Self::Meta, ) -> Result<Self, TensorError>
where Self::Meta: SampleUniform, <Self::Meta as SampleUniform>::Sampler: Sync,

Same as randint but the shape will be based on x. Creates a Tensor with random integers drawn uniformly from the half-open interval [low, high).

§Parameters:

low: Lower bound (inclusive) of the range.

high: Upper bound (exclusive) of the range.

§Example:
let x = Tensor::<i32>::randn(&[10, 10])?;
let r = x.randint_like(0, 100)?; // shape: [10, 10]

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§