in reply to Simulating Drawing From A Bag

For your code as it is.
To save typing you can define your bag array with range; You don't need to use the $i variable at all
Use $#bag as your argument to rand instead to generate a random number between 0 and the last index of the array
. You also don't need to change the value of $x at all.
This would give you
#!/usr/bin/perl -w use strict; my @my_bag; @my_bag = (1..10); while (@my_bag > 0) { my $x = int(rand($#my_bag)); print splice(@my_bag, $x, 1) . "\n"; }
Shuffling via rand and splice isn't very efficient though on large arrays. Have a look at perldoc -q shuffle for an example of a fisher-yates shuffle