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 7762689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:28:21+00:00 2026-06-01T14:28:21+00:00

Lets just put it at its simplest, a table with two fields: ‘item_id’ &

  • 0

Lets just put it at its simplest, a table with two fields: ‘item_id’ & ‘times_seen’.

| item_id | times_seen |
----------+-------------
|   1001  |     48     |
|   1002  |     25     |
|   1003  |      1     |
|   1004  |     12     |
|   1005  |     96     |
|   1006  |     35     |

I’m trying to find a way to randomly select a row, but give preference to items that haven’t been selected much before.

(obviously, a second query would be sent to increment the ‘times-seen’ field after it has been selected)

Although my current “project” is a php/mysql one, I’d like language agnostic solutions if possible. I’d much rather have a math based solution that could be adapted elsewhere. I’m not opposed to a php solution though. I’d just like to be able to understand how the code works rather than just copy and paste it.

  • 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-06-01T14:28:23+00:00Added an answer on June 1, 2026 at 2:28 pm

    How about a SQL solution:

    select * from item order by times_seen + Rand()*100 limit 1;
    

    How much you multiply random with (Its a value between 0 and 1) depends on how much randomness you want..

    Edit: http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I
There's a nice plugin for Frog CMS that lets you just type in yourpicture.120x120.jpg
I just wrote my first web service so lets make the assumption that my
I've just discovered that Oracle lets you do the following: SELECT foo.a, (SELECT c
Lets say I have hierarchy like this (This is just a test program. Please
Lets say I have the string: MyNamespace.SubNameSpace.MyClassName How do I extract just everything after
I just learned about ngrep , a cool program that lets you easily sniff
This is just a question to help me understand CSS rendering better. Lets say
just a question that needs a quick answer, I have a Action, lets say,
I'm new to using OOP, I typically just put all my code in a

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.