A fortune cookie message is selected by drawing a secure unsigned 32-bit random value, rejecting values in the incomplete remainder, and mapping an accepted value evenly to one message in the chosen pool.

The Fortune Cookie Generator uses that method for 36 original, Lizely-authored English micro-messages. You can draw from the complete pool or narrow it to Focus, Curiosity, Creativity, or Everyday before generating. The filters, random draw, and current result operate locally in your browser tab.

Here, “fortune” refers to the familiar cookie format rather than a prediction. A generated line can serve as a playful writing prompt, icebreaker, placeholder card, or small moment of novelty; it is not a forecast or decision tool.

how is a message selected when i generate fortune cookie
How Is a Message Selected in Fortune Cookie Generator?

What happens when you select Generate message

The selection process has a fixed order. The chosen category determines which messages are eligible before the browser produces any random value, and the result panel does not appear until you explicitly request a draw.

  • The category control builds the eligible message pool. All categories uses all 36 messages, while a single category uses its nine messages.
  • The browser’s Web Crypto API supplies a fresh secure unsigned 32-bit value for the Generate action.
  • The selection function checks whether that value falls in the incomplete tail that would create an uneven remainder.
  • A rejected value triggers another secure draw; an accepted value maps evenly to a valid entry in the selected pool.
  • The result panel displays the selected category and the full message line.

An unsigned integer is simply a whole number with no negative sign. The 32-bit range provides a fixed space of possible values from which the selector can reject a small remainder and preserve equal treatment of every message.

Why rejection sampling prevents uneven picks

A simple random-number calculation often takes the random value modulo the number of available messages. That works cleanly only when the full range of random values divides evenly by the pool size. Here, the 32-bit range is not evenly divisible by most pool lengths, so a direct remainder operation could give messages near the beginning of the list a tiny advantage.

The selector instead calculates the largest complete multiple of the pool length below 2^32. It rejects values in the incomplete tail and retries with new secure values. The accepted range can then be divided into equal-sized index blocks, leaving every message with the same number of possible accepted values.

For example, Focus contains nine messages. The 32-bit space has 4,294,967,296 values, and 4,294,967,296 = 9 × 477,218,588 + 4. The selector accepts 4,294,967,292 values and rejects the final four. Dividing that accepted range into nine equal blocks gives every Focus message the same selection probability.

In normal browser use, the component calls globalThis.crypto.getRandomValues. It does not use Math.random, Date.now, a random draw during rendering, or a server endpoint. A 128-attempt safety boundary prevents endless retries if the injected random source is broken. If the browser’s random source fails, the output is cleared and the interface displays an explicit browser-support message.

Choose the pool that determines the eligible messages

The category filter is applied before the random draw, so it changes which messages can be selected without changing the selection method itself.

Choice Eligible messages What the pool contains
All categories 36 The complete original library across all four message styles.
Focus 9 Gentle observations about small tasks and clear starts.
Curiosity 9 Questions, unusual angles, and playful connections.
Creativity 9 Notes about drafts, constraints, remixes, and unfinished ideas.
Everyday 9 Light scenes involving pages, pens, walks, music, snacks, fresh air, browser tabs, and chairs.

Changing the category clears the previous result. That prevents a line selected from one category from remaining visible under a new category label. Reset also returns the category control to All categories.

Use this sequence to create a message and decide whether to keep, copy, or clear it.

  1. Open the Fortune Cookie Generator and choose All categories for the complete pool, or select Focus, Curiosity, Creativity, or Everyday to narrow the eligible messages.
  2. Select Generate message. The browser requests a fresh secure value, and the selector applies rejection sampling before mapping an accepted value to a message.
  3. Read the result panel, which shows the selected category and the complete message line.
  4. Select Copy message if you want to use the line elsewhere. The Clipboard API is accessed only after this user action, and the tool reports either a successful copy or a clear manual-copy fallback.
  5. Select Reset when you want to clear the output. The tool removes the result, changes the category back to All categories, and returns the panel to its stable idle state.

To obtain another line, select Generate message again rather than Reset. If the browser denies clipboard access, the visible message remains available for manual copying.

What each control changes

Control Confirmed behavior Important boundary
Category Rebuilds the eligible pool and clears any previous result. It does not submit a question, name, birthday, or personal profile.
Generate message Requests a fresh secure value and displays the selected message. No message is chosen automatically when the page first appears.
Copy message Copies the visible line after a user action and reports success or a manual fallback. A denied clipboard permission does not remove the visible result.
Reset Clears the result, restores All categories, and shows the idle panel. It does not generate a replacement message.

Why generation waits for your button press

The initial idle state is intentional. No message exists until Generate message is selected, and loading the page does not consume a random draw. Keeping selection outside the render step also avoids server/client hydration differences and prevents a result from changing without a user action.

This explicit state makes the result easier to interpret: the idle panel has no selected line, a completed generation shows both its category and text, and Reset clearly returns to the starting state.

Privacy and interpretation limits

The generator is a playful text tool, not an advisory system. It does not analyze a question, accept a name or birthday, tailor output to a user, or produce individualized guidance. It generates no lucky numbers and makes no health, financial, relationship, legal, medical, or safety recommendations. The messages should not be used to make a decision.

All state remains in the current browser tab. The tool sends no prompt or selected result to a server and writes nothing to localStorage, sessionStorage, IndexedDB, or a user account. Clipboard access occurs only when Copy message is pressed. The random draw and message selection therefore remain in the browser rather than becoming part of a stored personal profile.

Overall, the message is chosen through a short, auditable path: establish the category pool, obtain a secure browser value, remove the biased remainder, map the accepted value to an equal-sized group of entries, and display the resulting original line.

Related reading: What Are Common Mistakes When I Generate a Fortune Cookie?.

Related reading: What Can Go Wrong When I Generate a Fortune Cookie?.