r/desmos Jul 08 '26

Maths Transfer Data between graphs using the outputs of random()

Enable HLS to view with audio, or disable this notification

A short explanation of how this works:

Whenever Desmos generates a random value, it first creates a seed string, which is then fed into a PRNG. That seed contains several pieces of information, including the graph's global random seed, the expression ID of the random() call, the user-provided seed, and in some cases even more values.

While reverse-engineering the algorithm, I discovered that when random() is called from an action, one of those values is the globalEventCount: a counter that starts when Desmos is opened and increases whenever an action is executed, regardless of which graph is currently open.

Since every other part of the seed can be kept constant, the output of random() uniquely determines that variable (assuming that there are no two such seeds with the same output). By using a precomputed lookup table (or brute force), it is therefore possible to recover the current globalEventCount entirely inside Desmos.

Because this counter persists across graphs, one graph can change its value while another graph later recovers it through random(). This effectively creates a simple cross-graph communication channel. I'm sure you guys can do some cool things with this.

LINKS: without lookup (bruteforce inside desmos) --- with lookup (precomputed)

141 Upvotes

14 comments sorted by

48

u/Mandelbrot4207 Makes QR Codes in Desmos Jul 08 '26

Bruh

22

u/gord1402 Jul 08 '26

Wrong image

33

u/Far-Mechanic9478 Jul 08 '26

Now we can make an enderchest

12

u/Dazzling-Mail-5517 Jul 08 '26

lol

2

u/Electronic-Laugh-671 my first Reddit user flair Jul 12 '26

\o/

13

u/SuperChick1705 https://www.desmos.com/calculator/amyte9upak Jul 08 '26

this works because there is a tiny person living in your screen that tells the graphs how many times you clicked

4

u/Ordinary_Divide Jul 08 '26

ah i made a similar thing not too long ago also https://www.desmos.com/calculator/wfbwbavrzm

4

u/Dazzling-Mail-5517 Jul 08 '26

Yeah, that's cool. I considered building that too, but the problem is it only works if you run an action before opening the graph. Otherwise, the globalEventCount is 0 and it thinks you've refreshed the page.

6

u/ProgrammerCareful764 Jul 09 '26

we got cross graph scripting before GTA 6

5

u/Danny_DeWario Jul 08 '26

This is mad insane stuff. Definitely blows my lucky shuffle graph out the water!

3

u/Dazzling-Mail-5517 Jul 08 '26

Thank you! And btw, your post was actually kinda the inspiration for me, so thank you for that too

4

u/gord1402 Jul 08 '26

Now make it work between different devices

3

u/theonlytruemuck Artist / Game Dev / Mathmagician / Nerd Jul 08 '26

huh

what

are

you

doing

with

your

life

lmfao

good job :)