---
title: "allocate(randomUniformUsing:range:shape:batchSize:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/bnnsndarraydescriptor/allocate(randomuniformusing:range:shape:batchsize:)-761hg"
---

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

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

## Declaration

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

## 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

Discussion Use this function to create a new array descriptor that’s initialized with random values 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 single-precision values between -10.0 and 10.0: guard     let randomGenerator = BNNS.RandomGenerator(         method: .aesCtr,         seed: 1234),     let descriptor = BNNSNDArrayDescriptor.allocate(         randomUniformUsing: randomGenerator,         range: Float(-10)...Float(10),         shape: [16]) else {         return     }

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

descriptor.deallocate()

## See Also

### Allocating and Deallocating Memory

- [allocate(initializingFrom:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(initializingfrom:shape:batchsize:).md)
- [allocate(randomUniformUsing:range:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(randomuniformusing:range:shape:batchsize:)-2rorb.md)
- [allocate(randomIn:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(randomin:shape:batchsize:)-1697a.md)
- [allocate(randomIn:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(randomin:shape:batchsize:)-5a2p2.md)
- [allocate(randomIn:using:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(randomin:using:shape:batchsize:)-5kbi8.md)
- [allocate(randomIn:using:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(randomin:using:shape:batchsize:)-3w6ig.md)
- [allocate(repeating:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocate(repeating:shape:batchsize:).md)
- [allocateUninitialized(scalarType:shape:batchSize:)](accelerate/bnnsndarraydescriptor/allocateuninitialized(scalartype:shape:batchsize:).md)
- [deallocate()](accelerate/bnnsndarraydescriptor/deallocate().md)
