There's no need to even have a while loop.
Set local var %i to the number of entries in the supplied section
var %i = $ini(legendary.ini,$$1,0)Note:
$$1 makes '
if ($1)' obsolete ("
/help $$")
Set %i to a random number between 1 and the number of entries from above ("
/help $rand")
var %i = $rand(1,%i)Those two steps can be combined..
var %i = $rand(1,$ini(legendary.ini,$$1,0))Now, because your entries are saved in nick=nick (item and value are the same) format, $ini() will return the result you're after.
echo -a $ini(legendary.ini,$1,%i)alias roll {
var %i = $rand(1,$ini(legendary.ini,$$1,0))
echo -a $ini(legendary.ini,$1,%i)
}