in reply to Creating a random generator
For the example you've given with colors, the code would be:
The first line makes a list of available choices and the second creates a number from 0 to (the number of options - 1), then prints the item at that position in the list. (List elements are numbered starting at 0 rather than 1, so this can produce any element in the list.)my @colors = qw(red yellow green cyan blue magenta white gray black); print $colors[rand @colors], "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a random generator
by grinder (Bishop) on Sep 06, 2007 at 14:41 UTC |