---
title: "SecRandomCopyBytes(_:_:_:)"
framework: security
role: symbol
role_heading: Function
path: "security/secrandomcopybytes(_:_:_:)"
---

# SecRandomCopyBytes(_:_:_:)

Generates an array of cryptographically secure random bytes.

## Declaration

```swift
func SecRandomCopyBytes(_ rnd: SecRandomRef?, _ count: Int, _ bytes: UnsafeMutableRawPointer) -> Int32
```

## Parameters

- `rnd`: The random number generator object to use. Specify doc://com.apple.security/documentation/Security/kSecRandomDefault to use the default random number generator.
- `count`: The number of random bytes to return in the array pointed to by the bytes parameter.
- `bytes`: A pointer to an array that the function fills with cryptographically secure random bytes. Use an array that is large enough to hold at least count bytes.

## Return Value

Return Value A result code set to errSecSuccess or some other value on failure.

## Discussion

Discussion Always test the returned status to make sure that the array has been updated with new, random data before trying to use the values. For example, to create 10 random bytes:
