go ahead... be a heretic | |
PerlMonks |
Re: Efficiently selecting a random, weighted elementby Skeeve (Parson) |
on Oct 16, 2006 at 13:08 UTC ( [id://578498]=note: print w/replies, xml ) | Need Help?? |
I'd not store the index, where the file begines, but the number of words in it. Searching is then done by substracting the number of words from the random number. As a final step, the file found is swapped with the last file and the number of words is substracted. As you can see, your selected files are now in the last n positions of the array. s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{% +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
In Section
Cool Uses for Perl
|
|