On Sep9, 8:07pm, Richard <richar...@gmail.com> wrote:
> hi,
>
> is there an efficient way to get a random record from a table?
> An obvious non-efficient way would be to get all the records and do
> random.choice().
>
> thanks,
> Richard


Would like to see comments on this.

  import random
  total_count = db(db.mytable.id>1).count() # well, this is one extra
db query
  random_id = random.randint(1, total_count)
  random_record = db.mytable[random_id] # Does this work on GAE?

Iceberg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to