Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Objective-C wrapper for Mersenne Twister, a (pseudo) random number generator.

branch: master

Initial commit.

latest commit a8de1fa1a7
Adam Preble authored September 03, 2012
Octocat-spinner-32 MTRandom.xcodeproj Initial commit. September 03, 2012
Octocat-spinner-32 MTRandom Initial commit. September 03, 2012
Octocat-spinner-32 MTRandomTests Initial commit. September 03, 2012
Octocat-spinner-32 .gitignore Initial commit. September 03, 2012
Octocat-spinner-32 README.markdown Initial commit. September 03, 2012
README.markdown

MTRandom

An Objective-C wrapper for Mersenne Twister, a pseudorandom number generator developed in 1997 by Makoto Matsumoto and Takuji Nishimura.

This Objective-C wrapper was written by Adam Preble in 2012.

Usage

This repo contains MTRandom, an Objective-C class encapsulating the Mersenne Twister generator.

MTRandom *random = [[MTRandom alloc] init];       // Seed the generator with the current time.
uint32_t q = [random randomUInt32];               // [0, 0xFFFFFFFF]
uint32_t r = [random randomUInt32From:5 to:10];   // [5, 10]
double   s = [random randomDouble];               // [0.0, 1.0]
double   t = [random randomDouble0To1Exclusive];  // [0.0, 1.0)
double   u = [random randomDoubleFrom:0 to:M_PI]; // [0, 3.14159...]

MTRandom conforms to NSCoding and NSCopying so you can archive it and copy it.

The repo also contains an Xcode project with a single target, MTRandomTests, which is a set of basic unit tests. You can run those tests by opening the Product menu and selecting Test.

License

The wrapper itself is BSD licensed, as is the version of Mersenne Twister itself that it is based on. If you use MTRandom, send me a note.

Something went wrong with that request. Please try again.