K
K
Karina2015-10-04 12:54:14
SQL
Karina, 2015-10-04 12:54:14

How to organize random with priority?

The task is this: there is a table with ratings. I randomly select a user (this is the first opponent), and then I randomly select the second opponent BUT! with the same rating as the first opponent.
In my table: user id and rating. SQL has a RANDOM function.
But I need such an algorithm: let random users fly out, but let users with a lower rating (I will set the range) drop out three times more often than users with a high one (I will also set the range).
How can this be implemented? And most importantly - what to read? (I can also use php)
Thank you all for your answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-10-04
@iKapex

Standard Algorithm for intervals:
Suppose that for every case of a higher rating of the enemy, there are two cases of equal and three cases of less.
Greater: 1
Equal: 2
Lesser: 3 Let
's sum, 1+2+3 = 6.
Find the boundary values:
Greater: [0, (0+1)] = [0, 1)
Equal: [1, 1+2) = [1, 3)
Smaller: [3, 3+3) = [3, 6)
Generate a random number X from 0 to 6.
If X < 1, then select an opponent with a higher rating
Otherwise, if X < 3, then select an opponent with with an equal rating
Otherwise, choose an opponent with an equal rating

A
Ai Lab, 2015-10-04
@vpuhoff

google on a weighted sample, on what and how to implement the third thing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question