AWS Builder Center
An Omikuji App Where Quantum Physics Decides Your Luck

An Omikuji App Where Quantum Physics Decides Your Luck

This fortune-telling app never rolls random numbers. A real quantum circuit decides your luck instead, and this post explains how, in plain English.

Cloud Engineer
At Japanese shrines, you shake a box of numbered sticks and get a fortune slip: Great Blessing, Blessing, or if you're unlucky, Curse. The number is random. A machine (or a monk) just shuffles things until you can't predict the outcome.
I wanted to try something different. What if the "randomness" wasn't randomness at all, but something that is genuinely undecided until the moment you look at it? That's not a metaphor. It's how quantum physics actually works, and  Amazon Braket  lets you build and run real quantum circuits from a laptop. So I built  Quantum Omikuji : a fortune-telling app where your luck is decided by measuring a quantum circuit, not by calling a random number function.

A qubit doesn't pick a side until you look

A normal computer bit is either 0 or 1. A quantum bit, or qubit, can be a mix of both at the same time. Physicists call this superposition. The classic example is a coin spinning in the air: while it spins, it isn't really heads or tails, it's some blend of both, and only when it lands (when you measure it) does it become one or the other.
Three qubits in superposition give you 8 possible outcomes at once, like 3 spinning coins landing in every combination from 000 to 111. That's exactly 8, which happens to be how many fortune levels a traditional omikuji has: Great Blessing, Blessing, Middle Blessing, Small Blessing, Half Blessing, Future Blessing, Curse, and Great Curse. So the plan became simple: build a 3-qubit circuit where each of the 8 outcomes lines up with one fortune, weighted so the odds match a real shrine (17% Great Blessing, 20% Curse, and so on). Then measure it once. Whatever the circuit collapses to is your fortune.

Turning percentages into quantum gates

The tricky part isn't the concept, it's the encoding. A qubit's chance of measuring 0 versus 1 is controlled by a rotation gate called Ry. Rotate it one way and you get mostly 0s, rotate it the other way and you get mostly 1s, and the angle in between gives you any probability you want:
def _theta(p_zero: float) -> float:
"""Rotation angle so P(bit=0) = p_zero"""
return 2.0 * math.acos(math.sqrt(p_zero))
For one qubit that's all you need. For three qubits sharing a single probability table, you need the second qubit's rotation to depend on what the first one measured, and the third qubit's rotation to depend on both. That's a small circuit pattern called a multiplexed rotation: rotate, then use a CNOT gate to flip the rotation depending on the earlier qubit's value. Stack three of these and you get a 15-gate circuit that turns 8 plain percentages into 8 quantum amplitudes.
I didn't fully trust my own math here, so before hooking it up to any UI, I asked the simulator for the full state vector and checked every one of the 8 probabilities against the target:
状態 運勢 目標 実際
000 大吉 0.1700 0.170000 OK
001 吉 0.3500 0.350000 OK
...
111 大凶 0.0200 0.020000 OK
All eight matched to nine decimal places. That check mattered more than it sounds. If I'd shipped this without verifying, a sign error in the multiplexer would have quietly skewed the odds, and nobody drawing a fortune would ever have known.

What happens when you click "Observe"

The app runs on Amazon Braket's  LocalSimulator , which simulates the quantum circuit's math on ordinary hardware. When you press the button, it takes exactly one measurement shot of the circuit, and that single result becomes your fortune. There's no  random.choice()  anywhere in the fortune-picking code. To show you it isn't cheating, the result screen also runs the same circuit 2,000 more times and draws a bar chart, so you can see your single draw sitting inside the full probability curve.
The frontend is a Next.js app on Vercel. It calls an API route, which in production forwards the request to an AWS Lambda function packaged as a container image, sitting in Tokyo (ap-northeast-1) with the Braket SDK installed inside it. The Lambda builds the circuit, runs the simulator, and ships back the fortune, the measured bits, and the histogram data as JSON. The whole round trip lands in well under a second once the Lambda is warm.



The permission wall nobody warned me about

Getting that Lambda talking to the internet was the one part that didn't go smoothly. I gave the function a public Function URL, set the auth type to  NONE , attached what the AWS docs call the default public-access policy, and called it with  curl . Every single request came back  403 Forbidden. AccessDeniedException , with no other detail.
My first guess was a permissions-propagation delay, so I waited. I waited longer. Still 403. It turned out that since October 2025, alongside the  lambda:InvokeFunctionUrl  permission I already had, a Function URL's resource policy also needs a separate  lambda:InvokeFunction  permission, scoped to calls that come through the URL specifically. If you create the URL from the AWS console, Lambda quietly adds both statements for you. If you create it with the CLI, like I did, you only get the one you explicitly asked for, and the request gets rejected without saying which permission is missing. One more command fixed it:
aws lambda add-permission --function-name quantum-omikuji \
--statement-id FunctionURLInvokeFunction \
--action lambda:InvokeFunction --principal '*' \
--invoked-via-function-url --region ap-northeast-1
The annoying part is that this isn't a one-time mistake, it's a trap that resets every time you script a new Function URL from the CLI instead of clicking through the console. I found the exact same missing permission on an older side project of mine that had been live and working for months. Worth checking any Lambda Function URL you've ever set up by hand.

Nine languages, one quantum coin

The last thing I added was a language switcher: Japanese, English, Chinese, Korean, French, German, Spanish, Portuguese, and Arabic, saved to  localStorage  so it remembers your choice. The fortune itself always shows the original kanji, since that's how omikuji are actually written, with a translated word underneath. Arabic also flips the whole page to right-to-left, except for the parts that have to stay left-to-right no matter the language, like the measured bit string  |110⟩  and the circuit diagram.

The code is on  GitHub , and the app itself is live at  quantum-omikuji.vercel.app . Today it runs on Braket's simulator, but the SDK works the same way against real quantum hardware, so a version that draws your fortune on an actual QPU is on the list. Until then, the luck is still real quantum uncertainty, just simulated instead of run on a physical chip. Give it a shake and see what you get.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article