Dart's String.hashCode Differs Between VM and JavaScript, Breaking Seeded Randomness
A developer discovered last week that the same date string produces different hashCode values in Dart depending on the compilation target, causing a seeded random number generator to pick different minutes on mobile versus web. Specifically, '2026-09-29'.hashCode returns 160143713 on the Dart VM and AOT builds but 374027133 when compiled to JavaScript via dart2js. This inconsistency is not a bug — Dart's documentation explicitly states that hashCode is not guaranteed to be stable across platforms or executions. The root cause is that Dart integers on the web are JavaScript numbers, which handle hashing differently. The recommended fix is to replace hashCode-based seeding with a deterministic byte-hashing algorithm such as FNV-1a, which produces consistent results across all Dart compilation targets.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in