Fix seeding bugs and correct release metadata for 0.3.0 - #5
Merged
Conversation
Code review of the 0.2.1 release turned up four correctness bugs and several pieces of packaging metadata that were valid per arduino-lint but wrong in effect. Correctness: - reseed() never set `initialized`, so a reseed() issued before the first noise() call was silently discarded by the lazy init in noise(), which reseeded from millis() instead. - Seeding went through randomSeed()/random(). randomSeed() ignores a seed of 0, so init(0)/reseed(0) did not seed at all; init() with no argument passes millis(), which is ~0 that early in a sketch, so the "automatic" seed frequently produced an identical table every boot. Arduino's PRNG also differs across AVR/ESP32/Teensy, so a given seed was not portable, and generatePerm() clobbered the sketch's own random() state. Replaced with a private xorshift32. - fbm() with octaves < 1 left maxValue at 0 and returned NaN, which callers feed straight into servo.write(). Now clamped to >= 1. generatePerm() now shuffles in place within perm[0..255] rather than into a 256-byte stack buffer that was allocated lazily from inside noise(). Packaging: - Dropped `depends=Servo,ESP32Servo,PWMServo`. library.properties has no per-architecture mechanism, so this installed all three servo libraries on every board for a library whose core API needs none of them. It also shadowed the Teensy core's bundled PWMServo. - `includes` no longer pulls SimplexServo.h into noise-only sketches. - Added `license=MIT` and replaced the GPL-3.0 LICENSE file, which contradicted the public-domain intent stated in the README and both source headers. - keywords.txt no longer advertises private members. Version is 0.3.0, not a patch: the PRNG change means a given seed produces different output than in 0.2.x. Verified: arduino-lint --compliance strict --library-manager submit is clean; all 3 examples compile for arduino:avr:uno, esp32:esp32:esp32 and teensy:avr:teensy41; the shuffle produces valid permutations and the seeding fixes were confirmed on the host. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The esp32 matrix job failed on PR #5 with a network timeout fetching the xtensa toolchain from GitHub releases, during "Install cores" and before any library code was compiled. The same commit passed the esp32 job in a sibling run, and re-running it went green, confirming it was transient. Retry core installs up to 3 times with a short backoff. A persistent failure still fails the job, so real breakage is not masked. Also restrict the push trigger to master and tags. Previously every PR commit ran the full matrix twice, once for push and once for pull_request, which doubled CI cost and doubled the exposure to exactly this kind of flake. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code review of the tagged 0.2.1 release.
arduino-lint --compliance strictpassed clean on 0.2.1 and all examples compiled, so the problems here are not spec violations — they are metadata that is valid but wrong in effect, plus four correctness bugs.Ships as 0.3.0, not a patch: the PRNG change means a given seed produces different noise than it did in 0.2.x. Anyone who saved a seed to reproduce a pattern will need to re-pick it.
Correctness fixes
reseed()before the firstnoise()call was silently discarded. It regenerated the table but never setinitialized, so the lazy init innoise()immediately overwrote it withinit(millis()).Seed
0did not seed, and the automatic seed rarely varied. Seeding went throughrandomSeed(), whose AVR implementation isif (seed != 0) srandom(seed);— soinit(0)/reseed(0)were no-ops.init()with no argument passesmillis(), which is ~0 that early in a sketch, so the "automatic random seed" path frequently produced an identical permutation on every board and every boot. Replaced with a private xorshift32, which also makes a given seed reproducible across AVR/ESP32/Teensy (Arduino's PRNG is not the same on all three) and stopsgeneratePerm()from clobbering the sketch's ownrandom()state.fbm()withoctaves < 1returned NaN.maxValuestayed at0.0, andscaledFbmpassed the NaN straight intoservo.write(). Now clamped to at least 1.generatePerm()also now shuffles in place withinperm[0..255]instead of into a separate 256-byte stack buffer that was allocated lazily from insidenoise()— on an Uno the servo example leaves 584 bytes for locals, so an unpredictable 256-byte frame was worth removing. This fell out of the rewrite rather than being separate work.Packaging fixes
Dropped
depends=Servo,ESP32Servo,PWMServo.library.propertieshas no per-architecture dependency mechanism, so this installed all three servo libraries on every board — for a library whose core noise API needs none of them. I confirmed the Teensy consequence locally: with Library Manager'sPWMServoinstalled alongside the Teensy core's bundled copy, the resolver reportsAlternatives for PWMServo.h: [PWMServo@2.1 PWMServo@2.1]and picks the sketchbook copy over the core's. The README now documents the per-board install as a table instead.includes=SimplexNoise.h— previously also listedSimplexServo.h, so the IDE dragged a servo library into noise-only sketches.License. The
LICENSEfile was GPL-3.0 while the README and both source headers said public domain. GPL-3 on an Arduino library is strong copyleft that propagates into users' sketches, which is almost certainly not the intent and contradicts Gustavson's public-domain original. Now MIT, withlicense=MITinlibrary.propertiesand the upstream public-domain attribution preserved.keywords.txtno longer advertisesmapNoise,fastFloor,dot,F2andG2— all private.Documentation fixes
The "What's New in v0.2.1" list claimed "Memory optimization: Uses PROGMEM for constant data to save RAM". Checking the
v0.1tag,static const uint8_t p[256] PROGMEMandpgm_read_bytewere already there — that bullet was never new. Also replaced the "True randomness" feature claim, added Library Manager install instructions, and pointed the release checklist atarduino/library-registryfor the first-time submission.CI
Stopped installing
PWMServofrom Library Manager. The Teensy core bundles it, and the LM copy shadowed the bundled one — CI was validating something Teensy users don't actually get. Verified Teensy still compiles without it.Verification
arduino-lint --compliance strict --library-manager submit— clean, no errors or warningsarduino:avr:uno,esp32:esp32:esp32,teensy:avr:teensy41— 9/9 compilefbm(0)andfbm(-3)finite, output ranges sane over 20k samplesreseed(555)→noise()andinit(555)→noise()now both yield0.397943084975239560,1,555,12345,0xFFFFFFFF: valid 256-permutation, upper half mirrored,permMod12consistentAVR cost: ~+142 bytes flash, +2 bytes RAM (xorshift is slightly larger than the
random()calls it replaced).Deliberately out of scope
permMod12[512]is 512 bytes of pure cache forperm[i] % 12; withperm[512]that's 1024 bytes, and the noise-only example still sits at 64% of an Uno's RAM. Biggest remaining win.doublethroughout is free on AVR but software-emulated on ESP32 and Teensy 4.x. Switching tofloatwould be a real speedup on two of the three CI targets but changes public signatures.🤖 Generated with Claude Code