0 && $roll{0} == 'd') { $howMany = 1; $tempCount = sscanf($roll, "d%i%c%i%c%i", $diceValue, $whichSign, $changeAmount, $switchBy, $throwSuccess); if($tempCount == 0 || $tempCount == 2 || $tempCount == 4 || $tempCount > 5) { return "There was an error in you input; please enter a string in the correct format (see below)."; } else if($tempCount == 1) { $out .= "Die rolled a ".rand(1, $diceValue)."
"; } else if($tempCount == 3) { $temp = rand(1, $diceValue); switch($whichSign) { case '+': $out .= "Die rolled a ".$temp."+".$changeAmount." = ".($temp + $changeAmount).".
"; $temp += $changeAmount; break; case '-': $out .= "Die rolled a ".$temp."-".$changeAmount." = ".($temp - $changeAmount).".
"; $temp -= $changeAmount; break; case '*': $out .= "Die rolled a ".$temp."*".$changeAmount." = ".($temp * $changeAmount).".
"; $temp *= $changeAmount; break; case '/': $out .= "Die rolled a ".$temp."/".$changeAmount." = ".($temp / $changeAmount).".
"; $temp /= $changeAmount; break; case '>': $out .= "Die rolled a ".$temp.": throw ".(($temp >= $changeAmount) ? "succeeded" : "failed")."
"; break; case '<': $out .= "Die rolled a ".$temp.": throw ".(($temp <= $changeAmount) ? "succeeded" : "failed")."
"; break; } } else if($tempCount == 5) { $temp = rand(1, $diceValue); switch($whichSign) { case '+': $out .= "Die rolled a ".$temp."+".$changeAmount." = ".($temp + $changeAmount).":"; $temp += $changeAmount; break; case '-': $out .= "Die rolled a ".$temp."-".$changeAmount." = ".($temp - $changeAmount).":"; $temp -= $changeAmount; break; case '*': $out .= "Die rolled a ".$temp."*".$changeAmount." = ".($temp * $changeAmount).":"; $temp *= $changeAmount; break; case '/': $out .= "Die rolled a ".$temp."/".$changeAmount." = ".($temp / $changeAmount).":"; $temp /= $changeAmount; break; } switch($switchBy) { case '>': $out .= " throw ".(($temp >= $changeAmount) ? "succeeded" : "failed").".
"; break; case '<': $out .= " throw ".(($temp <= $changeAmount) ? "succeeded" : "failed").".
"; break; } } } else { $tempCount = sscanf($roll, "%id%i%c%i%c%i", $howMany, $diceValue, $whichSign, $changeAmount, $switchBy, $throwSuccess); if($tempCount <= 1 || $tempCount == 3 || $tempCount == 5 || $tempCount > 6) { return "There was an error in you input; please enter a string in the correct format (see below)."; } else if($tempCount == 2) { for($i = 0; $i < $howMany; $i++) { $out .= "Die ".($i + 1)." rolled a ".rand(1, $diceValue).".
"; } } else if($tempCount == 4) { for($i = 0; $i < $howMany; $i++) { $temp = rand(1, $diceValue); switch($whichSign) { case '+': $out .= "Die ".($i + 1)." rolled a ".$temp."+".$changeAmount." = ".($temp + $changeAmount).".
"; $temp += $changeAmount; break; case '-': $out .= "Die ".($i + 1)." rolled a ".$temp."-".$changeAmount." = ".($temp - $changeAmount).".
"; $temp -= $changeAmount; break; case '*': $out .= "Die ".($i + 1)." rolled a ".$temp."*".$changeAmount." = ".($temp * $changeAmount).".
"; $temp *= $changeAmount; break; case '/': $out .= "Die ".($i + 1)." rolled a ".$temp."/".$changeAmount." = ".($temp / $changeAmount).".
"; $temp /= $changeAmount; break; case '>': $out .= "Die ".($i + 1)." rolled a ".$temp.": throw ".(($temp >= $changeAmount) ? "succeeded" : "failed")."
"; break; case '<': $out .= "Die ".($i + 1)." rolled a ".$temp.": throw ".(($temp <= $changeAmount) ? "succeeded" : "failed")."
"; break; } } } else if($tempCount == 6) { for($i = 0; $i < $howMany; $i++) { $temp = rand(1, $diceValue); switch($whichSign) { case '+': $out .= "Die ".($i + 1)." rolled a ".$temp."+".$changeAmount." = ".($temp + $changeAmount).":"; $temp += $changeAmount; break; case '-': $out .= "Die ".($i + 1)." rolled a ".$temp."-".$changeAmount." = ".($temp - $changeAmount).":"; $temp -= $changeAmount; break; case '*': $out .= "Die ".($i + 1)." rolled a ".$temp."*".$changeAmount." = ".($temp * $changeAmount).":"; $temp *= $changeAmount; break; case '/': $out .= "Die ".($i + 1)." rolled a ".$temp."/".$changeAmount." = ".($temp / $changeAmount).":"; $temp /= $changeAmount; break; } switch($switchBy) { case '>': $out .= " throw ".(($temp >= $changeAmount) ? "succeeded" : "failed").".
"; break; case '<': $out .= " throw ".(($temp <= $changeAmount) ? "succeeded" : "failed").".
"; break; } } } } } ?> Dice Roller
Type a dice string (aType a number like '40000' into the box below to have it converted into a sequence of words, like 'forty thousand'.
" />
Throw " size="1" /> dice, each die having " size="1" /> sides.
get the code
You can get the source code to the number converter here. It's copyright, but you can use it freely and modify it however you want. To convert a number, call the convertNumber function, passing the number you want to convert to the function. The function will return the converted number as a string.