Giter Site home page Giter Site logo

rand.c's Introduction

rand.c

A PCG based pseudo-random number generator for C.

Example

#include <stdio.h>
#include "rand.h"

int main() {
    // Initialize and seed a new pseudo-random number generator.
    struct rand rand = rand_seed(2468);

    // Here we'll generate a random latitude and longitude point
    double lat = rand_double(&rand) * 180.0 - 90.0;
    double lon = rand_double(&rand) * 360.0 - 180.0;

    printf("lat=%.8f, lon=%.8f\n", lat, lon);
}

// output:
// lat=18.22369031, lon=41.10615327

Functions

Basic

rand_seed      # initialize and seed a new pseudo-random number generator.
rand_uint32    # returns a pseudo-random 32-bit value.
rand_uint64    # returns a pseudo-random 64-bit value.
rand_int63     # returns a non-negative pseudo-random 63-bit integer.
rand_int31     # returns a non-negative pseudo-random 31-bit integer.
rand_double    # returns a pseudo-random double in [0.0,1.0).
rand_fill      # writes pseudo-random bytes to data.

Testing

$ cc -DRAND_TEST rand.c && ./a.out              # run tests

License

rand.c source code is available under the MIT License.

rand.c's People

Contributors

tidwall 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.