GithubHelp home page GithubHelp logo

mt64's Introduction

64-bit Mersenne Twister PRNG (MT19937-64)

A 64-bit Mersenne Twister pseudo-random number generator.

Example:

int main(int argc, char** argv) {
    MT64 mt;
    mt64_init(&mt);

    for (int i = 0; i < 10; i++) {
        uint64_t rand = mt64_gen_u64(&mt);
        printf("%llu\n", rand);
    }

    return 0;
}

Usage

Initialize a new generator:

void mt64_init(MT64* mt);

Seed/re-seed the generator (optional):

void mt64_seed_with_u64(MT64* mt, uint64_t seed);

If you don't seed the generator, it will be automatically seeded on first use with a random seed.

Generate a random number:

// Generates a uniformly-distributed random integer on the closed interval [0, 2^64 - 1].
uint64_t mt64_gen_u64(MT64* mt);

// Generates a uniformly-distributed random integer on the closed interval [0, 2^63 - 1].
int64_t mt64_gen_i64(MT64* mt);

// Generates a uniformly-distributed random integer on the half-open interval [0, n).
uint64_t mt64_gen_int(MT64* mt, uint64_t n);

// Generates a uniformly-distributed random double on the closed interval [0.0, 1.0]
// with 53 bits of precision.
double mt64_gen_f64_cc(MT64* mt);

// Generates a uniformly-distributed random double on the half-open interval [0.0, 1.0)
// with 53 bits of precision.
double mt64_gen_f64_co(MT64* mt);

// Generates a uniformly-distributed random double on the open interval (0.0, 1.0)
// with 52 bits of precision.
double mt64_gen_f64_oo(MT64* mt);

License

All code is released under the 3-clause BSD license.

This library is based on the original implementation by the algorithm's inventors, Takuji Nishimura and Makoto Matsumoto, which was released under the 3-clause BSD license.

mt64's People

Contributors

dmulholl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.