Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to show a user random data from an SQL database?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CO@MarkRichman - I don't think this is a duplicate, as I'm looking to get a random row that the user hasn't already seen, rather than just any random row. I'm also using SQLAlchemy, as opposed to actual SQL, to perform the queries
      singulars
    2. CO_My conundrum comes with making the presentation truly random - not showing the user the same information twice by remembering what they've seen and not showing them those already seen sets of data again._ Just a nitpick: by definition, you are making your data LESS random by doing that. Perhaps that IS what you need your application to do, but you are throwing people off when you say you are trying to make things _truly_ random and then describe something that is _less_ random than just picking any element.
      singulars
    3. COAs @MarkHildreth said, what you are looking for isn't truly random. What I would ask then is if do you need as complicated a solution for your use case. First, how are you indexing data? If it is the usual auto-index starting with 1, you could just store your latest (aka highest index), and do a random number in that range. Example: `random_id = str(random.randint(1, latest_id))` then `SELECT * FROM data WHERE id = random_id`. Which would be a bit faster than 'order by RAND'. I believe you could query the latest id when flask started and store it in memory, and then update it when needed.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload