perl -wle '@r = (1,2,3); print $r[$t = rand(3)]; print "$t"'; 2 1.28954588016495