Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4601866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:53:34+00:00 2026-05-21T23:53:34+00:00

Let’s say I have a collection of n objects, and that each object has

  • 0

Let’s say I have a collection of n objects, and that each object has a ranking associated with it, and these rankings correspond to the integer values 1 through n.

Now suppose that I want to select an object at random from the collection. But I don’t want to just pick a number from 1 to n at random; instead I want to make it so that I am more likely to pick a number higher up the list (with a ranking closer to 1).

Proposed solution: Instead of picking from 1 to n, pick from 1 to m, where m is some number significantly larger than n; then use some mapping function f : [1,m] → [1,n] that maps more numbers to the higher rankings than to the lower rankings. For instance, f(1), f(2), f(3) might all return 1, while f(m) is the only one which maps to n, so it is three times more likely to get 1 than n. Hopefully that makes sense.

So my question is: If this seems like a reasonable algorithm, what’s a reasonable function f that accomplishes this, and what ratio m/n would be large enough that integer rounding doesn’t prevent numbers from never getting picked?

[In my particular scenario, n can be pretty large (in the thousands), so solutions like the one presented here aren’t very practical for this situation. Also, the selection is “with replacement”; i.e. I pick an object once and then return; I don’t care if I pick it again immediately the next time.]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:53:35+00:00Added an answer on May 21, 2026 at 11:53 pm

    You can do something like the following:

    double bias = 1.5; 
    int index = (int)(n * (bias - sqrt(bias*bias -4.0*(bias-1.0)* random()))
                      / 2.0 / (bias-1));
    

    Changing the bias parameter lets you control how strongly you favor the higher ranked individuals.

    Edit: Here’s some python code for it.

    def pick(n, bias):
        return int(n * (bias - sqrt(bias*bias -4.0*(bias-1.0)*random())) / 2.0 / (bias-1))
    
    vals = [0]*10
    for i in xrange(1000):
        vals[pick(10,1.5)] += 1
    print vals
    [153, 151, 115, 116, 97, 96, 87, 69, 66, 50]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say that I have a set of relations that looks like this: relations
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say that I have a binary that I am building, and I include
Let's say that I have classes like this: public class Parent { public int
Let's say we have two concave 2d polygons(A, B), that don't intersect. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.