---
title: "randomTensor(withShapeTensor:descriptor:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/randomtensor(withshapetensor:descriptor:name:)"
---

# randomTensor(withShapeTensor:descriptor:name:)

Creates a Random op of type matching distribution in descriptor and returns random values.

## Declaration

```swift
func randomTensor(withShapeTensor shapeTensor: MPSGraphTensor, descriptor: MPSGraphRandomOpDescriptor, name: String?) -> MPSGraphTensor
```

## Parameters

- `shapeTensor`: 1D Int32 or Int64 tensor. The shape of the tensor generated
- `descriptor`: The descriptor of the distribution. See MPSGraphRandomOpDescriptor.
- `name`: The name for the operation.

## Return Value

Return Value An MPSGraphTensor of shape containing random values in the defined range.

## Discussion

Discussion Returns a tensor of provided shape of random values in the distribution specified. Uses a random seed value to initalize state. No state is preserved, and subsequent calls are not guaranteed to result in a unique stream of random values.
