Skip to content

Instantly share code, notes, and snippets.

@K-Francis-H
Created January 28, 2022 21:11
Show Gist options
  • Select an option

  • Save K-Francis-H/804d58701d1f7afaaed0bfc1b2ec4a8f to your computer and use it in GitHub Desktop.

Select an option

Save K-Francis-H/804d58701d1f7afaaed0bfc1b2ec4a8f to your computer and use it in GitHub Desktop.
A poly rolling hash implementation in OpenSCAD. Useful for making procedurally generated 3D objects with named seed values.
function poly_rolling_hash(seed, idx, hash, ppow, p, m) = len(seed) == idx ?
hash :
poly_rolling_hash(seed, idx+1, (hash + (ord(seed[idx]) - ord("a") + 1) * ppow) % m, (ppow * p) % m, p, m);
function seed_from_string(string) = poly_rolling_hash(string, 0, 0, 1, 31, pow(10,9)+9);
//how to use:
rand_val = rands(0, 100, 1, seed_value=seed_from_string("human readable seed") );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment