<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thanh Nguyen</title>
    <description>The latest articles on DEV Community by Thanh Nguyen (@thankvn).</description>
    <link>https://dev.to/thankvn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263658%2F291616d4-cf33-49fe-b11e-5cb14a1e2154.jpg</url>
      <title>DEV Community: Thanh Nguyen</title>
      <link>https://dev.to/thankvn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thankvn"/>
    <language>en</language>
    <item>
      <title>Same daily puzzle for everyone, no server: notes from building 7 offline puzzles in React Native</title>
      <dc:creator>Thanh Nguyen</dc:creator>
      <pubDate>Wed, 25 Nov 2026 01:50:40 +0000</pubDate>
      <link>https://dev.to/thankvn/same-daily-puzzle-for-everyone-no-server-notes-from-building-7-offline-puzzles-in-react-native-lcp</link>
      <guid>https://dev.to/thankvn/same-daily-puzzle-for-everyone-no-server-notes-from-building-7-offline-puzzles-in-react-native-lcp</guid>
      <description>&lt;p&gt;Hi DEV, I'm Thanh, a solo developer. I build &lt;strong&gt;AhaBox&lt;/strong&gt;, 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stack:&lt;/strong&gt; Expo SDK 54, React Native 0.81, Reanimated 4, AsyncStorage for local data, Google Mobile Ads.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. "Same puzzle for everyone" without a server
&lt;/h2&gt;

&lt;p&gt;The easy answer is a backend that serves today's puzzle. I wanted the games to work on a plane, so the puzzle is generated on the device from the date instead.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build a date key like &lt;code&gt;2026-11-25&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Hash it together with the game name (&lt;code&gt;daily_challenge_2026-11-25&lt;/code&gt;) into an integer.&lt;/li&gt;
&lt;li&gt;Feed that integer into a small deterministic PRNG (Park–Miller is enough for puzzles).&lt;/li&gt;
&lt;li&gt;Run the puzzle generator with that PRNG instead of &lt;code&gt;Math.random&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;seededRandom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seed&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2147483647&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;16807&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2147483647&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2147483646&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hashString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;|=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rng&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;seededRandom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hashString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`daily_challenge_${dateKey}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things matter if you do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Every random call has to go through the seeded PRNG, and in the same order.&lt;/strong&gt; If a generator retries ("this layout has two solutions, try again"), the retry has to use the same stream, so every phone takes the same path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't change the generator after release&lt;/strong&gt; without versioning the seed. Otherwise players on the old and new app versions see different puzzles on the same day.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. The 7 AM bug: UTC vs. local date
&lt;/h2&gt;

&lt;p&gt;My first version used &lt;code&gt;new Date().toISOString().slice(0, 10)&lt;/code&gt; as the date key. That's the UTC date. In Vietnam (UTC+7) the "daily" puzzle rolled over at 7 in the morning, so a player who solved it at 6:50 AM got a brand-new puzzle ten minutes later, and their streak logic got confused.&lt;/p&gt;

&lt;p&gt;The fix is boring but important: build the key from the device's local calendar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pad&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;localDateKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Parse it back as local midnight too (&lt;code&gt;new Date(y, m - 1, d)&lt;/code&gt;), not &lt;code&gt;new Date('2026-11-25')&lt;/code&gt;, which is UTC midnight. Every streak, "played today" flag and habit tracker in the app now uses the same helper.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. No network while playing
&lt;/h2&gt;

&lt;p&gt;Games and tools never call the network while you play. Scores, streaks, habits and focus sessions are stored on the phone in AsyncStorage, and there's no sign-up. Ads are the only part that needs a connection, and if they fail to load, the game just carries on.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Ads that don't ruin a 60-second game
&lt;/h2&gt;

&lt;p&gt;Short games and full-screen ads don't mix well, so the rules are strict:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;at most one interstitial every 3 rounds,&lt;/li&gt;
&lt;li&gt;at least 3 minutes apart, and a daily cap,&lt;/li&gt;
&lt;li&gt;rewarded ads are always opt-in,&lt;/li&gt;
&lt;li&gt;the 7 daily puzzles have no banners and no interstitials at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. A spoiler-free share card
&lt;/h2&gt;

&lt;p&gt;Each daily puzzle ends with a share card that shows your time and streak but not the solution, so people can post it in a group chat without spoiling it for friends.&lt;/p&gt;




&lt;p&gt;If you want to see how the daily puzzles play, the rules for each game are here: &lt;strong&gt;&lt;a href="https://ahabox.app/game/" rel="noopener noreferrer"&gt;AhaBox games&lt;/a&gt;&lt;/strong&gt;. The app is free with ads on Android, and iOS is coming soon.&lt;/p&gt;

&lt;p&gt;Happy to answer questions about seeded generation, streaks across time zones, or keeping 29 games in one React Native app.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>gamedev</category>
      <category>android</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
