There are many different ways I would write a $rand function.
The difficulty is to preserve backward compatibility since $rand already exists.
If I didn't have to worry about that though, here are some of the ways I might do it.

1. Each parameter is a single character or range of characters to be selected randomly from.
The result will be a single character picked from the list.

$rand(0-9,A-F) which would generate a random hexidecimal character.
$rand(0-9,A-Z,a-z,_,^,`,\,|,[,],{,},-) which would generate a random nickname character.
$rand(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,...etc) which would do the same.

2. Or like a regular expression class. Even include the []'s to help with backward compatibility.

$rand([][0-9A-Za-z_^`|{}\-]) generates a single nickname character.
$rand([][0-9A-Za-z_^`|{}\-]{9}) generates a string of 9 nickname characters.
$rand([][0-9A-Za-z_^`|{}\-]{1,9}) generates a string of $r(1,9) nickname characters.
Perhaps additional parameters could each have different ranges of characters.
$rand([][A-Za-z_^`|{}\], [][0-9A-Za-z_^`|{}\-]{8}) generates a real random nick. (no numbers or '-' for first character)

3. Dice roll syntex. Perhaps it's own $roll identifier.
$roll(5d20+4) == $calc($r(1,20) + $r(1,20) + $r(1,20) + $r(1,20) + $r(1,20) + 4)
There are too many varying roll syntex that exist, so I'll leave it with this simple example.

Just some of the ideas I had in mind anyway.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!