Random Card Deck

0

I'm creating a site for people playing cards with php. I would like to know how to create a deck of 50 cards for each person. In the database I have a table with 300 different cards and of these 300 cards I want the user to register generate 50 random cards of the 300 that I have in the table for his deck. I suppose it has to be with array and random.

    
asked by anonymous 26.08.2017 / 01:18

2 answers

2

You can use MySQL RAND () (I'm using PHP's PDO class to access bd):

    $pdo = new PDO($dsn, $dbuser, $dbpass);

    $sql = "SELECT * FROM sua_tabela ORDER BY RAND() LIMIT 50";
    $sql = $pdo->query($sql);

The variable $ sql is an array with 50 database values.

    
26.08.2017 / 01:49
1

For general use, the @Leandro response can be used. However for being a card game, although predictability is not something so easy ... it is still possible, so my comment.

Even by law in some cases, you need to use a truly random generator, dedicated hardware, or at least one CSPRNG. In poker websites that are regulated undergo testing, for example Gaming Labs, they have their own tests

26.08.2017 / 03:00