Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Efficiently selecting a random, weighted element

by jimt (Chaplain)
on Oct 10, 2006 at 16:40 UTC ( #577443=note: print w/replies, xml ) Need Help??


in reply to Re: Efficiently selecting a random, weighted element
in thread Efficiently selecting a random, weighted element

The average value (bytes/word) only optimizes out the word count step, which can be done fairly efficiently already (shell out to wc, if nothing else). Besides, for our purposes, averages weren't sufficient - it had to be exact.

From that point on, this approach is simply the second one I had detailed with the "aaa...b...cc..." array and it suffers from the same scalability problems. You've got 100 files with 3,000 words each and a 300,000 element array. My method ends up with a 100 element array.

You'll note that I didn't say "quickly", I said "efficiently". I was optimizing not only for execution time, but for memory storage. But yes, for smaller data sets, simply repeating the stored value n times is sufficient.

  • Comment on Re^2: Efficiently selecting a random, weighted element

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577443]
help
Chatterbox?
[stevieb]: Just need to implement an email plugin or something so I can get alerted remotely if the status of a build has changed from the last run
[stevieb]: Because of the extreme complexity of the testing code itself, I implemented extensive logging so I can troubleshoot much easier by setting a high debug level.
[stevieb]: if you're interested in the test/build backend, have a look at Test::BrewBuild.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-04-28 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (529 votes). Check out past polls.