This design is still under development!

Random Dice

Step 1:

Making a function we can call to execute the diceroll.


    function diceroll($choosen = 'D6'){
        
    }
        

Step 2:

Creating an array for collecting all the dicerolls for statistics, and then setting a choosen type. This can be set as a POST variable.


    $rolls = array();
    $choosen = 'D6';
        

Step 3:

The array containing the types of dices you can choose.


    $dices = array('D6' => 6, 'D10' => 10, 'D12' => 12);
        

Step 4:

Rolling the dice, the highest possible roll is taken from the choosen dice variable.


    $diceroll = mt_rand(1, $dices[$choosen]);
        

Step 5:

Adds the diceroll to the array for statistics


    $rolls[] = $diceroll;
    $_SESSION['Dicerolls'] = $rolls;
        

Step 6:

Unsetting the statistics array so you get a new start.


    if($_POST['reset']){
        session_unset($_SESSION['Dicerolls']);
    }
        

Final result:


    session_start();
    
    function diceroll($choosen = 'D6'){
        
        $rolls = array();
        
        $dices = array('D6' => 6, 'D10' => 10, 'D12' => 12);
        
        $diceroll = mt_rand(1, $dices[$choosen]);
        
        $rolls[] = $diceroll;
        $_SESSION['Dicerolls'] = $rolls;
        
    }
            

How to use: