Menu

Picking daily words without a server
📰

Picking daily words without a server

DEV Community: reactnative·Dilip Panicker·4 days ago
#93nmdrhF
#devtoreactnative#devto#dev#easy#list
Reading 0:00
15s threshold

Wordout is a Wordle-style game I built in React Native with Expo. It has three daily puzzles, Easy, Hard and Extreme, each with a different word, and everyone gets the same words on the same day. There is no backend; the app works the words out from the date.

The first version

The idea was to hash the date and read three indices out of the hash. I took UTC midnight as milliseconds, multiplied it by a big odd constant with Math.imul , and sliced bit ranges out of the result:

const seed = Math . imul ( dayMs , 2654435761 ) ; easy = list [ ( seed >>> 0 ) & 0x7FF ] hard = list [ ( seed >>> 11 ) & 0x7FF ] extreme = list [ ( seed >>> 22 ) & 0x7FF ]

Enter fullscreen mode

Exit fullscreen mode

(That is the shape of it; the real code also had spare slices and a % list.length .)

What was wrong

There are two problems, and they come from the same place.

The first is range. & 0x7FF keeps 11 bits, so an index can never exceed 2,047, and my answer list has 2,315 words. About 267 answers could never be picked.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.