squirrel_noise5

Crates.iosquirrel_noise5
lib.rssquirrel_noise5
version1.1.1
created_at2025-08-03 20:39:09.336495+00
updated_at2025-08-17 19:49:45.204633+00
descriptionImplementation of SquirrelNoise version 5 with a random values generator and optional bindings with rand crate (rand_squirrel feature)
homepage
repositoryhttps://github.com/PaulUlanovskij/squirrel_noise_5.rs
max_upload_size
id1780089
size23,740
Ulanovskyi Paviel (PaulUlanovskij)

documentation

README

Prelude of original .hpp file:

/////////////////////////////////////////////////////////////////////////////////////////////////

SquirrelNoise5 - Squirrel's Raw Noise utilities (version 5) This code is made available under the Creative Commons attribution 3.0 license (CC-BY-3.0 US): Attribution in source code comments (even closed-source/commercial code) is sufficient. License summary and text available at: https://creativecommons.org/licenses/by/3.0/us/

These noise functions were written by Squirrel Eiserloh as a cheap and simple substitute for the [sometimes awful] bit-noise sample code functions commonly found on the web, many of which are hugely biased or terribly patterned, e.g. having bits which are on (or off) 75% or even 100% of the time (or are excessively overkill/slow for our needs, such as MD5 or SHA).

Note: This is work in progress; not all functions have been tested. Use at your own risk. Please report any bugs, issues, or bothersome cases to SquirrelEiserloh at gmail.com.

The following functions are all based on a simple bit-noise hash function which returns an unsigned integer containing 32 reasonably-well-scrambled bits, based on a given (signed) integer input parameter (position/index) and [optional] seed. Kind of like looking up a value in an infinitely large [non-existent] table of previously rolled random numbers.

These functions are deterministic and random-access / order-independent (i.e. state-free), so they are particularly well-suited for use in smoothed/fractal/simplex/Perlin noise functions and out-of-order (or or-demand) procedural content generation (i.e. that mountain village is the same whether you generated it first or last, ahead of time or just now).

The N-dimensional variations simply hash their multidimensional coordinates down to a single 32-bit index and then proceed as usual, so while results are not unique they should (hopefully) not seem locally predictable or repetitive.

/////////////////////////////////////////////////////////////////////////////////////////////////

Fast hash of an int32 into a different (unrecognizable) uint32.

Returns an unsigned integer containing 32 reasonably-well-scrambled bits, based on the hash of a given (signed) integer input parameter (position/index) and [optional] seed. Kind of like looking up a value in an infinitely large table of previously generated random numbers.

I call this particular approach SquirrelNoise5 (5th iteration of my 1D raw noise function).

Many thanks to Peter Schmidt-Nielsen whose outstanding analysis helped identify a weakness in the SquirrelNoise3 code I originally used in my GDC 2017 talk, "Noise-based RNG". Version 5 avoids a noise repetition found in version 3 at extremely high position values caused by a lack of influence by some of the high input bits onto some of the low output bits.

The revised SquirrelNoise5 function ensures all input bits affect all output bits, and to (for me) a statistically acceptable degree. I believe the worst-case here is in the amount of influence input position bit #30 has on output noise bit #0 (49.99%, vs. 50% ideal).

Commit count: 0

cargo fmt