A Swift framework for generating random data across native types, Foundation, and CoreGraphics with protocol-oriented design.
RandomKit is a Swift framework designed to simplify random data generation across a wide range of types, from basic primitives to Foundation and CoreGraphics structures. It solves the problem of repetitive and inconsistent random value generation by providing a unified, protocol-oriented API that integrates seamlessly with Swift's type system.
Swift developers building iOS, macOS, watchOS, tvOS, or Linux applications that require random data for testing, simulations, games, or procedural content generation.
Developers choose RandomKit for its extensive type support, protocol-oriented extensibility, and multiple high-performance random generators, which reduce boilerplate and ensure consistent random data generation across different use cases.
Random data generation in Swift
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Custom types can easily integrate by conforming to protocols like Random and Shuffleable, enabling seamless random data generation for user-defined structures without boilerplate.
Supports various generators such as Xoroshiro, MersenneTwister, and ChaCha, allowing developers to choose based on performance and randomness quality needs, as detailed in benchmarks.
Provides thread-local generator instances via withThreadLocal methods to ensure safe random data generation in multi-threaded environments without shared mutable state.
Generates random values for Swift primitives, Foundation types like Date and NSColor, and CoreGraphics types such as CGPoint and CGRect, covering common iOS/macOS use cases.
Includes a benchmark.sh script to compare generator performance, helping developers optimize based on metrics like array generation times shown in the README.
Different generators have significant performance differences; for example, DeviceRandom is over 100 times slower than Xoroshiro in benchmarks, which could hinder real-time applications.
Compatibility with non-Apple and non-Linux platforms like Windows or Android is untested, limiting its reliability in broader cross-platform projects.
The extensive protocol system and multiple generator options can be overwhelming for developers who only need basic random number generation without advanced features.
For types like BigInt, separate extensions (e.g., RandomKitBigInt) are required, adding extra dependencies and setup overhead to the project.