in reply to Re: Pick random item from list of unknown length?
in thread Pick random item from list of unknown length?
print "Say ", ( m!([^,]+)!g )[ scalar rand( tr!,!! ) ], "\n";
Counting the commas will give you one less than the numbers of elements in the list so you have to add one to it:
print "Say ", ( /[^,]+/g )[ rand 1 + tr/,// ], "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Pick random item from list of unknown length?
by Cody Fendant (Hermit) on Mar 01, 2010 at 06:03 UTC | |
by Anonymous Monk on Mar 01, 2010 at 07:17 UTC | |
by Cody Fendant (Hermit) on Mar 01, 2010 at 22:28 UTC | |
|
Re^3: Pick random item from list of unknown length?
by Anonymous Monk on Mar 01, 2010 at 05:13 UTC |