Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io node.js Math.random get different results on all users

I'm currently developing a poker texas holdem application using node.js, socket.io and javascript.

The problem I'm having is when I try to shuffle the deck using a math.random function it shuffles the deck as intended but it shuffles the deck differently to for each user connected to the the application.

Basically I want to be able to shuffle the deck using some kind of random function but still shuffle it the same way for all users.

I'm using io.sockets.emit(); to use the shuffle function on all users.

like image 346
Fredrik Brodén Avatar asked Mar 07 '26 16:03

Fredrik Brodén


1 Answers

Shuffle the deck on the server side (node.js) and then send every user his cards and community cards.

like image 51
yakxxx Avatar answered Mar 10 '26 07:03

yakxxx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!