#!/usr/bin/tclsh

package require Tk

# Define dices list
set dices [ list 4 6 8 10 12 20 100 ]
set maxdices 5

proc dice { number dice } {
    global myFont
    # number : Destination for output
    # dice : max posibility for random (see dices list)
    set out 0
    set dis ""
    for { set i 1 } { $i <= $number } { incr i } {
        set val [ expr int(rand() * $dice)+1 ]
        set out [ expr $out + $val ]
        if { $i == 1 } {
            set dis $val
        } else {
            set dis "$dis, $val"
        }
    }
    set dis "$dis -> $out"
    .result  configure -font myFont -text "$dis"

    return $out
}

font create myFont -family Helvetica -size 18 -weight bold 

set count 0 
foreach dc $dices {
    label .l$count -font myFont -text "D$dc" 
    grid .l$count -row $count -column 0 
    for { set i 1 } { $i <= $maxdices } { incr i } {
        button .b$count$i -font myFont -text "$i" -command "dice  $i $dc" 
        grid .b$count$i -row $count -column $i
    }
    incr count
}
label .result -font myFont -text " "
grid .result -row $count -column 0 -columnspan [ expr $maxdices + 1 ] 

