Same daily puzzle for everyone, no server: notes from building 7 offline puzzles in React Native
Hi DEV, I'm Thanh, a solo developer. I build AhaBox , an Android app with 29 small brain games and 22 everyday tools (pomodoro timer, habit streaks, water reminder and so on). In the latest update I added seven daily puzzles, where everyone in the world gets the same puzzle each day. Here are a few notes from building them in React Native. Stack: Expo SDK 54, React Native 0.81, Reanimated 4,…
Thanh, a solo developer, crafted AhaBox, an Android application featuring 29 compact brain games and 22 daily tools such as a pomodoro timer and habit streaks. Recently, they incorporated seven daily puzzles accessible to everyone globally. Here are some insights into the development process.
The game's central feature is that every player receives the same puzzle daily, without the need for a server. The puzzle's creation is entirely reliant on the device's date. A date key, like '2026-11-25', is generated and hashed with the game name to produce an integer. This integer is then utilized in a deterministic pseudo-random number generator (PRNG) for puzzle generation, replacing Math.random. A seeded random function, seededRandom, is employed to ensure consistent generation across devices.
Two crucial aspects of the seeding process must be adhered to: every random call must pass through the seeded PRNG in the same sequence, and the generator shouldn't be modified post-release without updating the seed. This ensures that all players experience the same puzzle on the same day.
The initial version of the puzzle generator used the UTC date as the date key. However, this led to an issue in Vietnam, where the 'daily' puzzle would reset at 7 AM local time. To fix this, the date key is now generated from the device's local calendar, ensuring all players receive their puzzles at the same local time.
The application operates offline, storing scores, streaks, habits, and focus sessions locally using AsyncStorage. Ads are the only elements that require a network connection. If ads fail to load, the game continues uninterrupted. Furthermore, ads are strategically placed to avoid disrupting short games, with a maximum of one interstitial every 3 rounds, at least 3 minutes apart, and a daily cap. Rewarded ads are always opt-in, and daily puzzles contain no banners or interstitials.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to