Results 1 to 3 of 3

Thread: [RESOLVED] Grasping a weighted random

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Resolved [RESOLVED] Grasping a weighted random

    I have searched this forum, plus google and stackoverflow as well. I've seen examples, discussions, etc about the process. However, I'm still unable to grasp how it would be implemented in the design I have come up with.

    Background: I'm creating a music player with a custom rating for each song. Ratings are held in a sqlite database, all defaulted at 5. The ratings can go from 0 - 10. The whole idea is implemented when the random or shuffle toggle is on.

    It's easy for me to query all the songs with their ratings at once. I can return all these rows into a new ArrayList(), let's call it songratings if need be, all sorted according to rating, higher -> lower.

    The next part, I'm looking to pull a random number, that has more of a chance at the higher rated songs, but not a direct % must be played. Let's exclude 0 ratings from the arraylist, as 0 rated songs won't be played.

    So, if for example, I have songs rated 1-10, I'm most likely to hear the songs rated 8-10, decently likely to hear 6-7, middle is 5, less likely for 3-4, and least likely for 1-2.

    I'm trying to figure out something to this effect:
    Ratings: 10 - 14% chance
    9 - 14%
    8 - 13%
    7 - 12%
    6 - 11%
    5 - 10%
    4 - 8%
    3 - 7%
    2 - 6%
    1 - 5%

    I think I might have to pull a random to choose a percentage, then pull a random out of the ones with those ratings? Sorry for the long post, first time delving into random stuff...

    EDIT: Oops, forgot 1 major point -> ratings might not exist. For example, every song starts with a default rating of 5 and spans out from there. So, I need to sort of base it off the ratings range in the arraylist I think?
    Last edited by detlion1643; Feb 6th, 2012 at 10:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width