Created
January 28, 2022 21:11
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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