在php中制作一个coinflip(可公平)

so I'm trying to create website with a coinflip system (Its just a small project I'm doing in my free time) but I don't really know where to begin. I need to make it in php (so its in the backend) and I need it to be provably fair (so I can prove that it is legit). What I've found out is that I need to use something like sh256 but I also heard that its pretty out dated and can be easily cracked. Also if it matters it's a site with a steam login system so I plan on being able to join 1v1's with others steam users not just a person sitting besides me or something (not just 1 button is what I mean hehe).

EDIT: I have googled it and tried asking people I know and etc if they knew anything but nothing was any good.

Thanks in advance

-Eiríkur

This is a simple way to get a random coin toss result:

$result = array("heads", "tails")[random_int(0,1)];

First, we make an array, which will be our choices. array("heads, "tails") means we will always get one of those 2 results. Next, in the same line, we can select a single element to actually assign to the $result variable from the array we made previously. We can use random_int(min, max) to generate that number.

Note: random_int() generates cryptographic random integers that are suitable for use where unbiased results are critical, such as when shuffling a deck of cards for a poker game. http://php.net/manual/en/function.random-int.php

As a bonus, you could add more elements to this array, and then just increase the max value in random_int(), and it will work. You could make this more dynamic as-well by doing it like this:

$choices = ["heads", "tails", "Coin flew off the table"];
$result = $choices[random_int(0, count($choices)-1];

With the above code, you can have as many choices as you'd like!


Testing

I ran this code 50,000 times, and these were my results.

Array
(
    [heads] => 24923
    [tails] => 25077
)

And I ran this code 100,000 times, these were my results:

Array
(
    [tails] => 49960
    [heads] => 50040
)

You can play around with this here, to check out results:

https://eval.in/894945