<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/randomPhiloxStateTensor(withSeed:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)randomPhiloxStateTensorWithSeed:name:"
  },
  "title" : "randomPhiloxStateTensor(withSeed:name:)"
}
-->

# randomPhiloxStateTensor(withSeed:name:)

Creates a tensor representing state using the Philox algorithm with given counter and key values.

```
func randomPhiloxStateTensor(withSeed seed: Int, name: String?) -> MPSGraphTensor
```

## Discussion

Generates random numbers using the Philox counter-based algorithm, for further details see:
John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw. Parallel Random Numbers: As Easy as 1, 2, 3.
A stateTensor generated with this API can be used in MPSGraph Random APIs which accept a stateTensor. The
updated stateTensor is returned alongside the random values, and can be fed to the following random layer. In
most use cases, a stateTensor should only need to be initialized once at the start of the graph. A stateTensor can
be set as a target tensor of an MPSGraph execution to obtain a stateTensor serialized as an NDArray. This can be
used as input to a placeholder in the graph to avoid ever needing to have a state intilization layer in an MPSGraph.
This can allow for a continued stream through multiple executions of a single MPSGraph by having the final
stateTensor as a target tensor passed into the following MPSGraph execution as a placeholder input. This may be
helpful for training graphs in particular.

```md
MPSGraph *graph = [MPSGraph new]; 
MPSGraphTensor *stateTensor = [graph randomPhiloxStateTensorWithSeed: seed name: nil]; 
NSArray<MPSGraphTensor*> *resultTensors0 = [graph randomUniformTensorWithShape:

- Parameters:
  - seed: Initial counter and key values will be generated using seed.
  - name: Name for the operation
- Returns: An MPSGraphTensor representing a random state, to be passed as an input to a random op.
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)