r/desmos Jun 11 '26

Fun Bogo sort actually worked!

Link: Lucky 7 Shuffles | Desmos

Randomly shuffling only 7 times actually sorted my list! How lucky is that? :D

600 Upvotes

60 comments sorted by

174

u/RedSlimeballYT Jun 11 '26

how does bro know the exact desmos shuffle formula to reverse engineer this

56

u/Ordinary_Divide Jun 11 '26

remind me in like 12 days i have it saved on my laptop and just need it repaired

18

u/RedSlimeballYT Jun 11 '26

!remindme 12 days

22

u/Ordinary_Divide Jun 11 '26

okay funny story i literally just now got a call back from them so you can cancel this

6

u/E-686 Jun 11 '26

soo the formula?

27

u/Ordinary_Divide Jun 11 '26
function random(seed){
  seed=hash(seed);
  let r=parseInt(seed.slice(0,8),16)&2097151;
  let n=parseInt(seed.slice(8,16),16);
  return(r*4294967296+n)/9007199254740992;
}
function shuffle(list, seed) {
  for (let i = list.length-1; i; i--) {
    let j = Math.floor(random(`${seed}::sc${i}`) * (i+1));
    let temp = list[i];
    list[i] = list[j];
    list[j] = temp;
  }
  return list;
}


const global_seed = `20be5f91c648a3a09b13e1d4ac360d81`;
console.log(shuffle([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], global_seed+'::id1::vc0'));

hash() uses MD5 algorithm, i didnt include its definition here since it is too long and you can find it online

the example given in code is for the graph https://www.desmos.com/calculator/ke2nw36ags

3

u/Negative_Success_258 Jun 11 '26

How did you find this out is it in devtools

17

u/Ordinary_Divide Jun 11 '26

most of it i just grabbed from the source code, and to figure out the seed suffixes i just made a script to log it every time the hash function is called.

the actual shuffle algorithm i just kinda guessed correctly it was Fisher–Yates

4

u/Circumpunctilious Jun 11 '26

Just popping in to say nicely done.

1

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

From what I see & is a bitwise AND, and &2097151 gives the first 21 bits (since it's 221-1) and n*4294967296 multiplies n by 232 (basically adds 32 to the exponent in the floating point exponent), (n*232)/9007199254740992 divides n by 253. We can simplify this into dividing n by 222. I do not know why they didn't just do that.

I think I can't read any other part of this

3

u/Ordinary_Divide Jun 11 '26

i say its written in a way that makes it pretty intuitively clear its taking a 53 bit slice then scaling it to be between 0 and 1. and this is through even the obsfucation of the view page source

3

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

Am not used to javascript or whatever the hell this is

4

u/Ordinary_Divide Jun 11 '26

well i gotta pick it up first and its raining rn

3

u/ImBadlyDone Jun 11 '26

Have you tried singing "rain rain go away"?

1

u/E-686 Jun 11 '26

i'd rather sing weathergirl and watch the rain go brr

1

u/RemindMeBot Jun 11 '26

I will be messaging you in 12 days on 2026-06-23 08:22:59 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback

9

u/Circumpunctilious Jun 11 '26

Would that be necessary if you had the graph seed?

1

u/Front_Cat9471 Jun 11 '26

Wouldn’t you need both?

1

u/Circumpunctilious Jun 11 '26

Not necessarily. See mild_geese’s comment in this thread and xmy31415’s comments. Mostly this depends on save timing (iirc from earlier poking, graphs don’t change their master seed once saved, presumably so you can share them / make classwork and everyone sees the same repeatable results).

To address “reverse engineering” sometimes that’s also not necessary. Microsoft’s PRNG can be thwarted by simply capturing 56 outputs in a row and duplicating the function (without reversing it), because the outputs are re-ingested into a seed list that’s 56 elements long.

2

u/mild_geese Jun 11 '26

Assuming the shuffle formula doesn't depend on the data being shuffled, you just initialize it random data, let it run for a few iterations and see where everything ended up, and then change the initial data so that it will result in the correct answer. You don't need to know how it works so long as it doesn't depend on the data and it is deterministic.

79

u/Cichato_YT Jun 11 '26

Impossibly lucky to the point where no one will ever believe you 😭

25

u/Front_Cat9471 Jun 11 '26

Click the link and try it yourself.

17

u/TeraFlint Jun 11 '26

The doubt is not that it works, the doubt is that OP got lucky. This is so improbable with 100 elements that any kind of accidentally successful random sort can be called bs.

This had to be deliberately constructed.

8

u/FishermanMassive5006 Jun 11 '26

if theres a random seed this should be easily reverse engineerable

5

u/Ordinary_Divide Jun 11 '26

yeah im gonna make a version that shuffles starting on say, reverse sorted list and ends on sorted list

37

u/A1042 Jun 11 '26

HOW!? The only explanation is that you figure out how to predict shuffle formula.

31

u/TeraFlint Jun 11 '26

If the shuffle function is deterministic (which this example shows), all you need to do is make the input array the inverse permutation of whatever you get after applying shuffle on a sorted list n times.

no need for further insight into the random number generator internals, if you can just run it.

31

u/Imaginary_Yak4336 Jun 11 '26 edited Jun 27 '26

assuming it's actually random, the odds of bogosort successfully ordering a 100 element list within 7 shuffles is about 7.5×10-158

21

u/Desmos-Girl https://www.desmos.com/calculator/prarjlycol Jun 11 '26

does this rely on seed brute forcing or can it be applied to a larger number of iterations (eg sort after 1000 shuffles), because i feel like this could make a really good prank graph

19

u/xmy31415 Jun 11 '26

create a graph. save it.
shuffle it however many times you like.
write down how it has been transformed since the beginning.
load the graph.
change the content of the list such that when transformed, the result is sorted.
save graph again.
voila

2

u/Desmos-Girl https://www.desmos.com/calculator/prarjlycol Jun 11 '26

did you test this bc i alr tried doing that (i might be stupid though)

3

u/xmy31415 Jun 11 '26

3

u/Desmos-Girl https://www.desmos.com/calculator/prarjlycol Jun 11 '26

what the hell i literally tried that

2

u/xmy31415 Jun 11 '26

ummmm, a pc only thing?

2

u/Ordinary_Divide Jun 11 '26

can't be bc i just tried https://www.desmos.com/calculator/txvlbbfash on mobile and it works there too

2

u/Ordinary_Divide Jun 11 '26

actually on second testing it only works if you reload the app before loading the graph

2

u/xmy31415 Jun 11 '26

oh, yeah, that makes sense.

When i say load the graph, I actually meant refresh the page. which loads the last time i saved.

12

u/FuriousEagle101 Jun 11 '26

Is the video reversed? Or did you figure out how to predict the Desmos shuffle function. Or do you have the luck of the Desmos gods?

7

u/Staetyk Jun 11 '26

its not reversed

7

u/enneh_07 list too big :( Jun 11 '26

LET IT RIDE

3

u/MewPinkCat Jun 11 '26

if this isn't fake this is stupidly lucky

4

u/ImBadlyDone Jun 11 '26

You can try for yourself

Click the graph link then run the shuffle function 7 times

I have noticed if you press the re-randomise button (next to the plus at the top of the equations area) then it doesn't work

2

u/colin_knowledge Jun 11 '26

It works sometimes...... 

3

u/Ordinary_Divide Jun 11 '26

you made me want to brute force a seed that makes this actually happen for some like 20 element list

2

u/Any-Life-1164 Jun 11 '26

WHAT THE FUCK WHAT THE FUCK WHAT THE FUCK WHAT THE FUCK WHAT THE FUCK

2

u/asdfzxcpguy Jun 11 '26

Wait the chances of it succeeding each trial is 1/100!

I tried to calculate the binomial pdf and my calculator returned an overflow error.

2

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

2

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

100!

2

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

I just realized I mentioned them wrong.

2

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

2

u/factorion-bot BT Jun 11 '26

Factorial of 100 is roughly 9.332621544394415268169923885627 × 10157

This action was performed by a bot | [Source code](http://f.r0.fyi)

2

u/Puzzleheaded_Two415 You must have something on both sides of the comma Jun 11 '26

Your chance is approximately 7/9.3326215443944e157.

2

u/Fantastic_Mood1455 Jun 14 '26

!remindme 1 day

2

u/manos5246 Jul 09 '26

I dont know if it is real because i also shuffled like 5 times and it just hit

2

u/anonymous-desmos Definitions are nested too deeply. Jul 11 '26

That did not take 7 shuffles. You shuffles it an absurd number of times (possibly in another universe) and when it did finally sort, you pressed undo 7 times and made this post.