GithubHelp home page GithubHelp logo

rnvannatta / vanity-hash Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 20 KB

Vendored collection of hashing and PRNG functions for usage in Vanity Scheme

License: MIT License

Makefile 0.13% C 99.15% C++ 0.72%

vanity-hash's Introduction

PRNG and Hashes for Vanity Scheme

This is just a vendored collection of excellent hashing and prng functions, glued into a single header file with a thin wrapper over the originals. These are used in Vanity Scheme

This collection is currently licensed under MIT.

Install Instructions

Copy include/vhash.h into your project. It is compatible with C99 and C++17. Good performance requires 128 bit multiplication support. The hashing function does unaligned reads, though it should be endianness safe.

Usage

uint64_t seed = 0xDEADBEEF;
// Fast General purpose non-cryptographic hash
uint64_t hash1 = vhash("hello, world!", sizeof "hello, world!", seed);

// Faster small value non-cryptographic hash, use for objects <= 8 bytes
// Also use to glue two hashes together, eg in hashing linked lists
uint64_t hash2 = vhash64(12345, seed);

// Fastest small value non-cryptographic hash, but invertible & no seeding
uint64_t hash3 = vhash64_quick(12345);

int threadid = 0;
vrandom_state rng;

// Setup rng state. the 3rd parameter provides multiple streams per
// seed, eg for multithreading.
vsrandom(&rng, seed, threadid);

// Get a uniform integer from 0 to 2^32-1
uint32_t randint = vrandom(&rng);

// Get a uniform integer from 1 to 20
int d20 = vrandom_bounded(&rng, 20) + 1;

// Get a uniform double from 0 to 1
double U0 = vrandom_double(&rng);

// Rewind the rng 1 step and get the same result
vrandom_advance(&rng, -1);
double U1 = vrandom_double(&rng);
assert(U0 == U1);

vanity-hash's People

Watchers

Richard Van Natta 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.