Let say Client1 has a big array in browser (javascript). Client2 has the same array.
Now when Client1 click Shuffle button, this array will sort by randomly. The problem is I want to sync this new order to Client2.
The idea is I don't want to send all item over network to Client2 because it's big. Then I think about a function array.shuffle(n)
where n is a random number. The shuffle function use n to sort array somehow. And when I send n
to Client2, it call the same function and get the same order of array.
Is there a function like that ?
Asked
Active
Viewed 113 times
1

boygiandi
- 630
- 10
- 20
-
You'd need to use server-side coding languages such as PHP or Node.JS – Jack Bashford Mar 01 '19 at 04:07
-
ok, but how ? can you give me some code – boygiandi Mar 01 '19 at 04:08
-
You can use any shuffle algorithm you want as long as it gets its randomness from a zero-entropy seedable PRNG, like this one: http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html . Just use the same seed in both. – Paul Mar 01 '19 at 04:10
-
2Here we don't write code for you - we fix code you already have. – Jack Bashford Mar 01 '19 at 04:10
-
Alternatively you could send the final permutation over the network, a lot more info than a seed, but you can still skip sending all the contents of the array. – Paul Mar 01 '19 at 04:11
-
@JackBashford yea. At least give some useful information in your comment. Server side have nothing to do in this case – boygiandi Mar 01 '19 at 15:57
2 Answers
0
You can use Fisher–Yates shuffle Algorithm. It shuffles based on random number which you can send to client2 and achieve the same shuffling.

Shubham Chaudhary
- 499
- 2
- 7
0
I found it
- Javascript random ordering with seed
- https://www.npmjs.com/package/shuffle-seed
- https://github.com/LouisT/SeededShuffle
Just use the right keyword from @Paulpro comment

boygiandi
- 630
- 10
- 20