A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
randu
ArrayFire Functions | ArrayFire Functions by Category » Functions to create and modify Arrays » Functions to create arrays. » Random Number Generation

Create a random array sampled from uniform distribution. More...

## Functions
AFAPI array | randu (const dim4 &dims, const dtype ty, randomEngine &r)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array | randu (const dim4 &dims, const dtype ty=f32)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array | randu (const dim_t d0, const dtype ty=f32)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array | randu (const dim_t d0, const dim_t d1, const dtype ty=f32)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array | randu (const dim_t d0, const dim_t d1, const dim_t d2, const dtype ty=f32)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array | randu (const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const dtype ty=f32)
| C++ Interface to create an array of random numbers uniformly distributed.
AFAPI af_err | af_random_uniform (af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type, af_random_engine engine)
| C Interface to create an array of uniform numbers using a random engine.
AFAPI af_err | af_randu (af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)

## Detailed Description

Create a random array sampled from uniform distribution.

The type of engine used is defined by af::randomEngine.

The data is uniformly distributed between [0, 1].

## Function Documentation

## ◆ af_random_uniform()

AFAPI af_err af_random_uniform | ( | af_array * | out,
|  | const unsigned | ndims,
|  | const dim_t *const | dims,
|  | const af_dtype | type,
|  | af_random_engine | engine )

C Interface to create an array of uniform numbers using a random engine.

Parameters

  [out] | out | pointer to the returned object
  [in] | ndims | number of dimensions
  [in] | dims | C pointer with `ndims` elements; each value represents the size of that dimension
  [in] | type | type of the af_array object
  [in] | engine | random engine object

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ af_randu()

AFAPI af_err af_randu | ( | af_array * | out,
|  | const unsigned | ndims,
|  | const dim_t *const | dims,
|  | const af_dtype | type )

Parameters

  [out] | out | generated array
  [in] | ndims | number of dimensions
  [in] | dims | array containing sizes of the dimension
  [in] | type | type of array to generate

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ randu() [1/6]

AFAPI array randu | ( | const dim4 & | dims,
|  | const dtype | ty,
|  | randomEngine & | r )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | dims | dimensions of the array to be generated
  [in] | ty | type of the array
  [in] | r | random engine object

Returns
  random number array of size `dims`

Examples
  graphics/conway.cpp, graphics/conway_pretty.cpp, and graphics/gravity_sim.cpp.

## ◆ randu() [2/6]

AFAPI array randu | ( | const dim4 & | dims,
|  | const dtype | ty = f32 )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | dims | dimensions of the array to be generated
  [in] | ty | type of the array

## ◆ randu() [3/6]

AFAPI array randu | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const dim_t | d3,
|  | const dtype | ty = f32 )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | d3 | size of the fourth dimension
  [in] | ty | type of the array

Returns
  random number array of size `d0` x `d1` x `d2` x `d3`

## ◆ randu() [4/6]

AFAPI array randu | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const dtype | ty = f32 )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | ty | type of the array

Returns
  random number array of size `d0` x `d1` x `d2`

## ◆ randu() [5/6]

AFAPI array randu | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dtype | ty = f32 )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | ty | type of the array

Returns
  random number array of size `d0` x `d1`

## ◆ randu() [6/6]

AFAPI array randu | ( | const dim_t | d0,
|  | const dtype | ty = f32 )

C++ Interface to create an array of random numbers uniformly distributed.

Parameters

  [in] | d0 | size of the first dimension
  [in] | ty | type of the array

Returns
  random number array of size `d0`