0

in mysql currently I am using order by RAND() DESC which works fine except i also have a number that counts number of likes which ranges from 0 to 5 right now but 5 could increase in the future let's call 5 my maxlikes

How can order it in such a way that the ones with more likes has more probability of showing up more often but still randomly show the ones with fewer likes from time to time?

Tin Tran
  • 6,194
  • 3
  • 19
  • 34
  • I ended up selecting a `max(rand()) as my order` when i count likes so that each like gives it an equal chance of showing up so the items with a lot of likes can have multiple opportunity to get a high (like each like is like a lottery ticket kind'a idea). – Tin Tran Nov 10 '17 at 00:16

1 Answers1

1

You could order by RAND()*likes DESC favors highly liked things
or something like order by RAND()*maxLikes +Likes DESC add maxLikes/2 on average to rank

it really depends on what you want the distribution to be I think you could also
select columns, rankingFormulaWithRandom as rank .... order by rank desc

mavriksc
  • 1,130
  • 1
  • 7
  • 10
  • I didn't use this because distribution is too much in favor of liked, i wanted a like to act like an extra entry so i selected `max(rand()) as my order` on the same line when i count my likes so that the ones with many likes get multiple opportunity to get high rank (but keeping everything equal like extra entries in a random lottery). – Tin Tran Nov 10 '17 at 00:19