What if you do get lucky?
You buy a $1 lottery ticket every month (12 times a year) and compete against everyone else on Earth. Every month, one random ticket wins, and the winner gets half of all the money collected. How many years until you win, and will you have spent more than you win?
This demo is for demonstration purposes only. A short math formula answers this question instantly: on average you'd wait players ÷ 12 years (about 675 million years for 8.1 billion players), and you'd come out ahead only about 39% of the time. Here, we deliberately simulate the real games instead, one draw at a time, to show how fast the GPU runs billions of independent draws, and to find out what happens to you in one particular lifetime of games. Every run uses new random numbers, so try again: maybe this time you get lucky.
Choose the number of players, and press "Play until I win".
How it works: each month is one draw. To pick a random winner among all players, the GPU generates a 64-bit random number per month, and you win when it falls in your share of the range (1 in players). A Web Worker sends the draws to the GPU in batches of up to 268 million months, where each GPU invocation checks 256 consecutive months, and an atomic operation records the earliest winning month in each quarter of the batch. Only those 4 numbers are read back. The batch size adapts to the measured GPU time, so that each submission takes about 100 ms on fast and slow GPUs alike. The shader skips months past the batch's month count, so a shorter batch is covered by a partial last workgroup. Without WebGPU, the worker runs the same draws on the CPU, which is much slower, so try a smaller number of players.
Test the CPU fallback
- Any browser: add
?cputo the page URL to skip WebGPU in this demo. - Chrome or Edge: start the browser with WebGPU turned off, for example
google-chrome --disable-features=WebGPU --user-data-dir=/tmp/no-webgpu(the separate profile directory makes the flag apply even if the browser is already running). - Firefox: set
dom.webgpu.enabledtofalseinabout:config. - Safari: turn off WebGPU in Develop > Feature Flags.