---
title: "BNNSRandomFillUniformFloat(_:_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/bnnsrandomfilluniformfloat(_:_:_:_:)"
---

# BNNSRandomFillUniformFloat(_:_:_:_:)

Fills the specified tensor with random floating-point values from the continuous uniform distribution within a range.

## Declaration

```swift
func BNNSRandomFillUniformFloat(_ generator: BNNSRandomGenerator?, _ desc: UnsafeMutablePointer<BNNSNDArrayDescriptor>, _ a: Float, _ b: Float) -> Int32
```

## Parameters

- `generator`: The random number generator.
- `desc`: The descriptor of the destination.
- `a`: The lower bound of distribution.
- `b`: The upper bound of distribution.

## Discussion

Discussion Use this function to fill an array descriptor with uniformly distributed random values. 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. If the descriptor’s data_type isn’t 32-bit floating point, the values that you specify for the bounds must be exactly representable in the descriptor’s data type. The following code populates a descriptor with random floating-point values: let data = UnsafeMutableBufferPointer<Float>.allocate(capacity: 8) var descriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),                                        layout: BNNSDataLayoutVector,                                        size: (10, 0, 0, 0, 0, 0, 0, 0),                                        stride: (0, 0, 0, 0, 0, 0, 0, 0),                                        data: data.baseAddress!,                                        data_type: BNNSDataType.float,                                        table_data: nil,                                        table_data_type: BNNSDataType.float,                                        data_scale: 1, data_bias: 0)

guard let randomNumberGenerator = BNNSCreateRandomGenerator(BNNSRandomGeneratorMethodAES_CTR,                                                             nil) else {     return }

BNNSRandomFillUniformFloat(randomNumberGenerator,                            &descriptor,                            -10,                            10)

print(Array(data))

data.deallocate() BNNSDestroyRandomGenerator(randomNumberGenerator)

## See Also

### Random number generation

- [BNNS.RandomGenerator](accelerate/bnns/randomgenerator.md)
- [BNNSCreateRandomGenerator(_:_:)](accelerate/bnnscreaterandomgenerator(_:_:).md)
- [BNNSCreateRandomGeneratorWithSeed(_:_:_:)](accelerate/bnnscreaterandomgeneratorwithseed(_:_:_:).md)
- [BNNSRandomGeneratorMethod](accelerate/bnnsrandomgeneratormethod.md)
- [BNNSRandomGenerator](accelerate/bnnsrandomgenerator.md)
- [BNNSRandomFillUniformInt(_:_:_:_:)](accelerate/bnnsrandomfilluniformint(_:_:_:_:).md)
- [BNNSRandomFillNormalFloat(_:_:_:_:)](accelerate/bnnsrandomfillnormalfloat(_:_:_:_:).md)
- [BNNSRandomFillCategoricalFloat(_:_:_:_:)](accelerate/bnnsrandomfillcategoricalfloat(_:_:_:_:).md)
- [BNNSRandomGeneratorStateSize(_:)](accelerate/bnnsrandomgeneratorstatesize(_:).md)
- [BNNSRandomGeneratorGetState(_:_:_:)](accelerate/bnnsrandomgeneratorgetstate(_:_:_:).md)
- [BNNSRandomGeneratorSetState(_:_:_:)](accelerate/bnnsrandomgeneratorsetstate(_:_:_:).md)
- [BNNSDestroyRandomGenerator(_:)](accelerate/bnnsdestroyrandomgenerator(_:).md)
