<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/randomGenerator()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)randomGeneratorFilter"
  },
  "title" : "randomGenerator()"
}
-->

# randomGenerator()

Generates a random filter image.

```
class func randomGenerator() -> any CIFilter & CIRandomGenerator
```

## Return Value

The generated image.

## Discussion

This method generates an image with infinite extent. The image pixels values are from one of four independent, uniformly distributed random colors.

The following code creates a filter that generates a random color image:

```swift
func random() -> CIImage {
   let randomGenerator = CIFilter.randomGenerator()
   return randomGenerator.outputImage!
}
```

![A random generator that displays random colors in each pixel.](images/com.apple.coreimage/media-3590973@2x.png)

---

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)