I would start by redesigning how you save your stats. Put them in a separate object and acess them by name. You need to make sure the object is initialised first, somewhere in StoryInit or so. And make sure you don't overwrite the current value.
<<set $stats = $stats || {}>>
Now you can access stats in two ways. Both are equivalent, so use whatever fits better.
<<set $stats.str = 12>>
<<set $stats["str"] = 12>>
Your code is almost unchanged.
<<set $r = ["str", "dex", "cool"]>>
<<set $r2 = $r.random()>>
<<if $stats[$r2] + random(1, 6) > 5>>
...
<</if>>
But now $stats [$r2] lets you modify the stat value too.
<<set $stats[$r2] -= 1>>