---
title: "ClikaRT::random::Generator"
sidebar_label: "Generator"
description: "class ClikaRT::random::Generator"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/compute/generator.h`

A random generator: the `{seed, counter}` state a random draw reads from. Every device holds one generator of its own, the device's DEFAULT: the `ops::` random functions draw from it, and `device::manual_seed` seeds it. A generator you create (`Generator::create(seed)`) draws its own sequence beside the device's through its draw methods (`gen.rand(...)`, `gen.multinomial(...)`, the whole family below): a request served with a seed beside unseeded ones reads the values it would read alone, and the device's sequence stays where it was. The draw math is counter-based, so one generator reads the same sequence on every device it draws on, and copies of a `Generator` refer to the same generator.

## Static member functions

### for\_device() {#for_device}

<div class="api-signature">

`static` [`Generator`](./Generator.md) **`for_device`**([`Device`](../Device.md) `device`)

</div>

[`device`](../device-namespace/index.md)'s default generator, the one [`device::manual_seed`](../device-namespace/index.md#manual_seed) seeds and the [`ops`](../ops/index.md)`::` random functions draw from on [`device`](../device-namespace/index.md).

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 45

</div>

### create() {#create}

<div class="api-signature">

`static` [`Generator`](./Generator.md) **`create`**(`std::uint64_t` `seed` `=` `0`)

</div>

A new generator of your own, seeded at [`seed`](./Generator.md#seed) with its counter at 0, independent of every device's default and of every other generator.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 49

</div>

## Member functions

### Generator() {#Generator}

<div class="api-signature">

**`Generator`**() `noexcept`

</div>

A generator meaning "the device's default": its draws read what the [`ops`](../ops/index.md)`::` random functions read. [`defined()`](./Generator.md#defined) reads false.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 41

</div>

### Generator(Generator) {#Generator-2}

<div class="api-signature">

**`Generator`**(`const Generator&` `other`)

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 51

</div>

### operator=(Generator) {#operator-assign}

<div class="api-signature">

[`Generator`](./Generator.md)`&` **`operator=`**(`const` [`Generator`](./Generator.md)`&` `other`)

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 52

</div>

### Generator(Generator) {#Generator-3}

<div class="api-signature">

**`Generator`**(`Generator&&` `other`) `noexcept`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 53

</div>

### operator=(Generator) {#operator-assign-2}

<div class="api-signature">

[`Generator`](./Generator.md)`&` **`operator=`**([`Generator`](./Generator.md)`&&` `other`) `noexcept`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 54

</div>

### \~Generator() {#Generator-4}

<div class="api-signature">

**`~Generator`**()

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 55

</div>

### defined() {#defined}

<div class="api-signature">

`bool` **`defined`**() `const noexcept`

</div>

True when this names a generator; false for the device-default form.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 58

</div>

### manual\_seed() {#manual_seed}

<div class="api-signature">

`void` **`manual_seed`**(`std::uint64_t` `seed`)

</div>

Seed this generator and reset its counter, so its next draws replay the seeded sequence from its start. Do not call while a draw reading it is in flight. On the device-default form: no effect (seed the device through [`device::manual_seed`](../device-namespace/index.md#manual_seed)).

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 64

</div>

### seed() {#seed}

<div class="api-signature">

`std::uint64_t` **`seed`**() `const`

</div>

The seed this generator draws from (the default seed, 0, on the device-default form).

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 68

</div>

### operator==() {#operator-eq}

<div class="api-signature">

`bool` **`operator==`**(`const` [`Generator`](./Generator.md)`&` `other`) `const noexcept`

</div>

Two handles compare equal when they name the same generator; two device-default forms compare equal.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 72

</div>

### operator\!=() {#operator-ne}

<div class="api-signature">

`bool` **`operator!=`**(`const` [`Generator`](./Generator.md)`&` `other`) `const noexcept`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 73

</div>

### rand() {#rand}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`rand`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Float32`](../../index.md#DataType),<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Uniform `[0, 1)` draws of `shape`, as [`ops::rand`](../ops/rand.md#rand).

**Parameters**

- `shape`: the output shape (each extent a scalar or 0-D tensor).
- `dtype`: output float dtype; default `Float32`.
- `device`: stream or device to allocate/run on; default = the default device.

**Returns:** a `shape`-shaped tensor of uniform draws.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float [`dtype`](../dtype/index.md).

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 88

</div>

### rand\_like() {#rand_like}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`rand_like`**([`Tensor`](../Tensor.md) `reference`, [`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`) `const`

</div>

Uniform `[0, 1)` draws shaped and typed like `reference`, as [`ops::rand_like`](../ops/rand_like.md#rand_like).

**Parameters**

- `reference`: the tensor whose shape and dtype the draws take.
- `device`: stream or device; default = `reference`'s.

**Returns:** uniform draws, shaped and typed like `reference`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `reference`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 97

</div>

### randn() {#randn}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`randn`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Float32`](../../index.md#DataType),<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Standard normal draws of `shape`, as [`ops::randn`](../ops/randn.md#randn).

**Parameters**

- `shape`: the output shape (each extent a scalar or 0-D tensor).
- `dtype`: output float dtype; default `Float32`.
- `device`: stream or device to allocate/run on; default = the default device.

**Returns:** a `shape`-shaped tensor of standard normal draws.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float [`dtype`](../dtype/index.md).

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 108

</div>

### randn\_like() {#randn_like}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`randn_like`**([`Tensor`](../Tensor.md) `reference`, [`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`) `const`

</div>

Standard normal draws shaped and typed like `reference`, as [`ops::randn_like`](../ops/randn_like.md#randn_like).

**Parameters**

- `reference`: the tensor whose shape and dtype the draws take.
- `device`: stream or device; default = `reference`'s.

**Returns:** standard normal draws, shaped and typed like `reference`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `reference`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 117

</div>

### randint() {#randint}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`randint`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `low`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `high`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Int64`](../../index.md#DataType),<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Integer draws in `[low, high)` of `shape`, as [`ops::randint`](../ops/randint.md#randint).

**Parameters**

- `low`: the lowest value drawn.
- `high`: one past the highest value drawn; above `low`.
- `shape`: the output shape (each extent a scalar or 0-D tensor).
- `dtype`: output integer dtype; default `Int64`.
- `device`: stream or device to allocate/run on; default = the default device.

**Returns:** a `shape`-shaped tensor of integer draws.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on an empty range, a non-integer [`dtype`](../dtype/index.md) or a range the dtype cannot hold.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 131

</div>

### randint\_like() {#randint_like}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`randint_like`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `reference`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `low`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `high`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Integer draws in `[low, high)` shaped and typed like `reference`, as [`ops::randint_like`](../ops/randint_like.md#randint_like).

**Parameters**

- `reference`: the tensor whose shape and dtype the draws take.
- `low`: the lowest value drawn.
- `high`: one past the highest value drawn; above `low`.
- `device`: stream or device; default = `reference`'s.

**Returns:** integer draws, shaped and typed like `reference`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on an empty range or a non-integer `reference`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 143

</div>

### uniform\_inplace\_impl() {#uniform_inplace_impl}

<div class="api-signature">

[`Result`](../Result.md)`<void>` **`uniform_inplace_impl`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `low`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `high`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device`<br />
) `const`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 145

</div>

### uniform\_() {#uniform_}

<div class="api-signature">

[`Tensor`](../Tensor.md)`&` **`uniform_`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `low` `=` `0.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `high` `=` `1.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

In-place: overwrite `self` with uniform draws in `[low, high)`, as [`ops::uniform_`](../ops/uniform_.md#uniform_).

**Parameters**

- `self`: the float tensor to fill.
- `low`: the range's lower bound (drawn); default 0.
- `high`: the range's upper bound (never drawn); default 1.
- `device`: stream or device; default = `self`'s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `self` or an empty range.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 154

</div>

### normal\_inplace\_impl() {#normal_inplace_impl}

<div class="api-signature">

[`Result`](../Result.md)`<void>` **`normal_inplace_impl`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `mean`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `stddev`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device`<br />
) `const`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 156

</div>

### normal\_() {#normal_}

<div class="api-signature">

[`Tensor`](../Tensor.md)`&` **`normal_`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `mean` `=` `0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `stddev` `=` `1`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

In-place: overwrite `self` with normal draws of `mean` and `stddev`, as [`ops::normal_`](../ops/normal_.md#normal_).

**Parameters**

- `self`: the float tensor to fill.
- `mean`: the mean, a scalar or a tensor broadcast over `self`; default 0.
- `stddev`: the standard deviation, a scalar or a tensor broadcast over `self`; default 1.
- `device`: stream or device; default = `self`'s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `self`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 165

</div>

### normal() {#normal}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`normal`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `mean`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `stddev`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Normal draws of `mean` and `stddev` shaped `shape`, as [`ops::normal`](../ops/normal.md#normal).

**Parameters**

- `mean`: the mean, a scalar or a tensor broadcast over the output.
- `stddev`: the standard deviation, a scalar or a tensor broadcast over the output.
- `shape`: the output shape (each extent a scalar or 0-D tensor).
- `device`: stream or device to allocate/run on; default = the default device.

**Returns:** a `shape`-shaped `Float32` tensor of normal draws.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a shape the operands cannot broadcast over.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 179

</div>

### exponential\_inplace\_impl() {#exponential_inplace_impl}

<div class="api-signature">

[`Result`](../Result.md)`<void>` **`exponential_inplace_impl`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `lambd`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device`<br />
) `const`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 181

</div>

### exponential\_() {#exponential_}

<div class="api-signature">

[`Tensor`](../Tensor.md)`&` **`exponential_`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `lambd` `=` `1.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

In-place: overwrite `self` with exponential draws of rate `lambd`, as [`ops::exponential_`](../ops/exponential_.md#exponential_).

**Parameters**

- `self`: the float tensor to fill.
- `lambd`: the rate, above 0; default 1.
- `device`: stream or device; default = `self`'s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `self` or a rate at or below 0.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 189

</div>

### bernoulli() {#bernoulli}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`bernoulli`**([`Tensor`](../Tensor.md) `probabilities`, [`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`) `const`

</div>

Independent Bernoulli draws from per-element success probabilities, as [`ops::bernoulli`](../ops/bernoulli.md#bernoulli).

**Parameters**

- `probabilities`: per-element success chances in `[0, 1]`; float dtype.
- `device`: stream or device; default = the input's.

**Returns:** 0/1 draws, same shape and dtype as `probabilities`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float input.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 199

</div>

### bernoulli\_inplace\_impl() {#bernoulli_inplace_impl}

<div class="api-signature">

[`Result`](../Result.md)`<void>` **`bernoulli_inplace_impl`**([`Tensor`](../Tensor.md)`&` `self`, [`StreamOrDevice`](../StreamOrDevice.md) `device`) `const`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 201

</div>

### bernoulli\_() {#bernoulli_}

<div class="api-signature">

`void` **`bernoulli_`**([`Tensor`](../Tensor.md)`&` `self`, [`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`) `const`

</div>

In-place: overwrite `self`, whose values are the per-element success probabilities, with the 0/1 draws, as [`ops::bernoulli_`](../ops/bernoulli_.md#bernoulli_).

**Parameters**

- `self`: the float tensor of success chances, filled with the draws.
- `device`: stream or device; default = `self`'s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float `self`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 208

</div>

### poisson() {#poisson}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`poisson`**([`Tensor`](../Tensor.md) `rates`, [`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`) `const`

</div>

Independent Poisson draws from per-element rates, as [`ops::poisson`](../ops/poisson.md#poisson).

**Parameters**

- `rates`: per-element rates at or above 0; float dtype.
- `device`: stream or device; default = the input's.

**Returns:** the counts, same shape and dtype as `rates`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-float input.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 217

</div>

### randperm() {#randperm}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`randperm`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `n`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Int64`](../../index.md#DataType),<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

A random permutation of `0 .. n-1`, as [`ops::randperm`](../ops/randperm.md#randperm).

**Parameters**

- `n`: the permutation's length, a scalar or a 0-D tensor.
- `dtype`: output integer dtype; default `Int64`.
- `device`: stream or device to allocate/run on; default = the default device.

**Returns:** an `[n]` tensor holding each of `0 .. n-1` once.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-integer [`dtype`](../dtype/index.md) or a negative `n`.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 229

</div>

### multinomial() {#multinomial}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`multinomial`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `probabilities`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `num_samples`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `replacement` `=` `false`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

Categorical draws from per-row weights, as [`ops::multinomial`](../ops/multinomial.md#multinomial).

**Parameters**

- `probabilities`: `[.., C]` non-negative weights per row (not necessarily normalized); float dtype.
- `num_samples`: draws per row.
- `replacement`: draw with replacement; default false (then `num_samples` is at most `C`).
- `device`: stream or device; default = the input's.

**Returns:** `Int64` category indices, `[.., num_samples]`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when a weight is negative or `num_samples` exceeds `C` without replacement.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 243

</div>

### random\_inplace\_impl() {#random_inplace_impl}

<div class="api-signature">

[`Result`](../Result.md)`<void>` **`random_inplace_impl`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `low`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `high`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device`<br />
) `const`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 245

</div>

### random\_() {#random_}

<div class="api-signature">

[`Tensor`](../Tensor.md)`&` **`random_`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md)`&` `self`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `low` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `high` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
) `const`

</div>

In-place: overwrite the integer tensor `self` with draws in `[low, high)`, or over the dtype's whole range when both bounds are unset, as [`ops::random_`](../ops/random_.md#random_).

**Parameters**

- `self`: the integer tensor to fill.
- `low`: the lowest value drawn; set with `high` or not at all.
- `high`: one past the highest value drawn; set with `low` or not at all.
- `device`: stream or device; default = `self`'s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on a non-integer `self`, a half-set range or an empty one.

<div class="api-declared">

Declared in `ClikaRT/compute/generator.h`, line 257

</div>
