Module onejoker::utils

source ·
Expand description

wiki | General utility functions

Functions that are probably available in the standard libraries for general use, but implemented here to be more specifically tailored and optimized for card games.

Constants§

  • Lookup table for binomial coefficients up to 63c63, calculated additively with Pascal’s triangle method at compile time.

Functions§

  • wiki | Calculate binomial coefficient Calculate the binomial coefficient “n choose k” using a lookup table. Is only valid for n, k in the range 0..=63.
  • wiki | Iterate over combinations Given an array of indices into a larger array, increment the 0-based indices to the next k-combination, returning true when done.
  • wiki | A simple xoshiro128++ PRNG I know, I know, first rule of PRNG club is don’t roll your own, just use the library. But I’m pretty sure I’m one of the few people who understands this stuff well enough to bend that rule a bit, and I just don’t like the standard library of either Dart or Rust for this application.
  • wiki | Random integer within range Return a random integer uniformly distributed in range [0, limit) with no division, using rejection sampling. The mask m is created to minimize rejections, which will be at worst 50%.
  • wiki | Standard Fisher-Yates shuffle
  • wiki | Slightly specialized heapsort Heapsort optimized for small sets like poker hands, and in descending order which is most useful for ranking and displaying poker hands.