Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm not lazy enough. Consider the following case. I'm working on a soccer simulation that assigns players a score for each of 4 attributes. For example midfielders will have a passing attribute between 6 and 21 , shooting attribute between 6 and 12, and so on. I want to tweak the distribution to a "bell shaped curve" so that most of the players are assigned a score in the midpoint of the range, and fewer are assigned a high or low score. My solution was to create a file with 100 values like this:
  • lines with score of 6 3
  • score of 7 5
  • score of 8 6
  • ...
  • score of 12 13
  • ...
  • score of 21 2
I read the file into an array, generate a random number, and assign the value in  @array[$rand] to a player.

There must be an easier and more perlish way to do this, but I'm having trouble visualizing a data structure that would do it. Any suggestions?


Dave
Code On!

Edit by BazB, fix sig div tag.


In reply to Efficient ways of storing a data set for random access by dthacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2023-06-02 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?