<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomUniformUsing:range:shape:batchSize:)-2rorb",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:So21BNNSNDArrayDescriptora10AccelerateE8allocate18randomUniformUsing5range5shape9batchSizeABSgAC4BNNSO15RandomGeneratorC_SNyxGAK5ShapeOSitAC10BNNSScalarRzSBRzlFZ"
  },
  "title" : "allocate(randomUniformUsing:range:shape:batchSize:)"
}
-->

# allocate(randomUniformUsing:range:shape:batchSize:)

Returns a new array descriptor that’s initialized with random integer values from the continuous uniform distribution.

```
static func allocate<Scalar>(randomUniformUsing: BNNS.RandomGenerator, range: ClosedRange<Scalar>, shape: BNNS.Shape, batchSize: Int = 1) -> BNNSNDArrayDescriptor? where Scalar : BNNSScalar, Scalar : BinaryFloatingPoint
```

## Parameters

`randomUniformUsing`

The random number generator that provides random values.

`range`

The range of random values.

`shape`

The shape of the n-dimensional array descriptor.

`batchSize`

The number of batches of data.

## Discussion

Use this function to create a new array descriptor that’s initialized with random values [`BNNS.RandomGenerator`](/documentation/Accelerate/BNNS/RandomGenerator) generates.

If you use the same generator on multiple threads, note that this function serializes the generator through an internal lock. To eliminate this contention, use different generators for each thread.

The following code creates a 16-element 1D tensor that contains random 16-bit integer values between `-10` and `10`:

```swift
guard
    let randomGenerator = BNNS.RandomGenerator(
        method: .aesCtr,
        seed: 1234),
    let descriptor = BNNSNDArrayDescriptor.allocate(
        randomUniformUsing: randomGenerator,
        range: Int16(-10)...Int16(10),
        shape: [16]) else {
        return
    }

// Prints 16 random values.
print(descriptor.makeArray(of: Int16.self)!)

descriptor.deallocate()
```

---

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)