<commit_before>package DDG::Goodie::Dice;
# ABSTRACT: roll a number of (abstract) dice.
# https://en.wikipedia.org/wiki/Dice_notation

use strict;
use DDG::Goodie;
use Lingua::EN::Numericalize;

triggers start => "roll", "throw";

zci answer_type => "dice_roll";
zci is_cached => 0;

my %utf8_dice = (
    1 => "\x{2680}",
    2 => "\x{2681}",
    3 => "\x{2682}",
    4 => "\x{2683}",
    5 => "\x{2684}",
    6 => "\x{2685}",
);

# roll_dice generate pseudo random roll
# param $_[0] number of faces
# return roll
sub roll_die {
    return int(rand($_[0])) + 1 if $_;
}

# set_num_dice set the number of dice to be rolled
# param user input x, ex. 'xd4' or 'x dice'
# param default for no label, ex. 'd20' or 'dice'
# return the number of dice to be rolled
sub set_num_dice {
    my $num_dice = $_[0];
    my $num_dice_default = $_[1];
    if(defined($num_dice)){
        if ($num_dice eq "a") {
            return 1;
        }
        elsif ($num_dice =~ /^[a-zA-Z\s\-]+$/) {
            return str2nbr($num_dice);
        }
        if ($num_dice ne ''){
            return $num_dice;
        }else{
            return $num_dice_default;
        }
    }else{
        return 1;
    }
}

# shorthand_roll_output generate shorthand roll output
# param array of rolls
# param sum of rolls
# return roll output
sub shorthand_roll_output {
    my @rolls = @{$_[0]};
    my $sum = $_[1];<commit_msg>dice improved test-2<commit_after>package DDG::Goodie::Dice;
# ABSTRACT: roll a number of (abstract) dice.
# https://en.wikipedia.org/wiki/Dice_notation

use strict;
use DDG::Goodie;
use Lingua::EN::Numericalize;

triggers start => "roll", "throw";

zci answer_type => "dice_roll";
zci is_cached => 0;

my %utf8_dice = (
    1 => "\x{2680}",
    2 => "\x{2681}",
    3 => "\x{2682}",
    4 => "\x{2683}",
    5 => "\x{2684}",
    6 => "\x{2685}",
);

# roll_dice generate pseudo random roll
# param $_[0] number of faces
# return roll
sub roll_die {
    return int(rand($_[0])) + 1 if $_;
}

# set_num_dice set the number of dice to be rolled
# param user input x, ex. 'xd4' or 'x dice'
# param default for no label, ex. 'd20' or 'dice'
# return the number of dice to be rolled
sub set_num_dice {
    my $num_dice = $_[0];
    my $num_dice_default = $_[1];
    if(defined($num_dice)){
        if ($num_dice eq "a dice") {
            return 1;
        }
        elsif ($num_dice =~ /^[a-zA-Z\s\-]+$/) {
            return str2nbr($num_dice);
        }
        if ($num_dice ne ''){
            return $num_dice;
        }else{
            return $num_dice_default;
        }
    }else{
        return 1;
    }
}

# shorthand_roll_output generate shorthand roll output
# param array of rolls
# param sum of rolls
# return roll output
sub shorthand_roll_output {
    my @rolls = @{$_[0]};
    my $sum = $_[1];
{'fraction_non_alphanumeric': 0.15810135617416132, 'fraction_numerical': 0.0324768022840828, 'mean_word_length': 2.58898847631242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6575198', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1050, 'n_words': 298}