For bit widths on
| k | size |
|
pop | runs | k (binary) |
|---|---|---|---|---|---|
| 0000009e | 00000073 | 0.449219 | 5 | 2 | 1..1111. |
| 00000076 | 0000006f | 0.433594 | 5 | 2 | .111.11. |
| 00000016 | 0000006e | 0.429688 | 3 | 2 | ...1.11. |
| // -*- coding: utf-8 -*- | |
| // | |
| // "Fast Primality Testing for Integers That Fit into a Machine Word" | |
| // | |
| #include <stdint.h> | |
| #include <stdbool.h> | |
| //───────────────────────────────────────────────────────────────────────────────── |
| // returns a 65 bit approximation of 1/d where the top bit is implied and | |
| // d is on (2^63, 2^64-1]: Floor[(2^128-1)/d]-2^64 | |
| // "Improved division by invariant integers", Moller & Granlund, 2011 | |
| // Algorithm 2, page 3. (https://gmplib.org/~tege/division-paper.pdf) | |
| // | |
| static inline uint64_t invert_u64_i(uint64_t d) | |
| { | |
| // Initial approximation from the top 9 bits (d9). Since the top bit is always set | |
| // this becomes a 256 entry table: | |
| // Table[Floor[(2^19 - 3 2^8)/d9], {d9, 256, 511}] |
| #include <math.h> | |
| #include <stdint.h> | |
| #include <string.h> | |
| // type pun helpers | |
| static inline uint64_t f64_to_bits(double x) | |
| { | |
| uint64_t u; memcpy(&u, &x, 8); return u; | |
| } |
| // result of internal core | |
| typedef struct { | |
| uint64_t r; // common odd factors | |
| uint32_t s; // common powers-of-two (as shift amount) | |
| } gcd_t; | |
| // core GCD routines: for 'm' significant bit & uniform inputs. | |
| // Probablity comments in each routine also assume the above. | |
| // | |
| // Expected number of iterations per method: |
| // compile with whatever then run PractRand: | |
| // ./test | RNG_test stdin64 -tlmin 256KB -tf 2 -tlmax 512GB -seed 0 | |
| //**************************************************************************** | |
| // verbatim from: https://prng.di.unimi.it/xoroshiro128plus.c | |
| /* Written in 2016-2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) | |
| To the extent possible under law, the author has dedicated all copyright | |
| and related and neighboring rights to this software to the public domain |
| // Repeating Cecil Hastings atan approximations from 1955 using Sollya. | |
| // Other than "amusement factor" these use Hasting's approximations | |
| // to "seed" the sollya calls to 'fpminimax'. | |
| // | |
| // Current world usage could include using an initial approximation | |
| // from some multiprecision or computer algebra system and then | |
| // Sollya to refine the constants to hardware sized (half,single,double,etc) | |
| // | |
| // Additionally the wide choice of the range would cause Sollya to fail | |
| // to converge if we didn't feed it an initial guess. |
| // Public Domain under http://unlicense.org, see link for details. | |
| // EXCEPT "CORE-MATH" marked section | |
| // {gcc,clang} -O3 -march=native -Wall -Wextra -Wconversion -Wpedantic -Wno-unused-function -fno-math-errno -ffp-contract=off atan_spitball.c -o atan_spitball -lm | |
| #include <stdint.h> | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| #include <string.h> |
For bit widths on
| k | size |
|
pop | runs | k (binary) |
|---|---|---|---|---|---|
| 0000009e | 00000073 | 0.449219 | 5 | 2 | 1..1111. |
| 00000076 | 0000006f | 0.433594 | 5 | 2 | .111.11. |
| 00000016 | 0000006e | 0.429688 | 3 | 2 | ...1.11. |
| // UNLICENSE or whatever other you want that doesn't hold me | |
| // responsible for you choosing to use any of this. | |
| // a sketch of a few niche things: | |
| // 1) generate a random number with a given population count | |
| // 2) perform a random bit permutation of the input | |
| // 3) not quite random versions of (2) | |
| // 4) use (2) or (3) to produce stateful variants of (1) | |
| #include <stdint.h> |