The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 17, 2019, 11:56:28 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Nutballs random selection problem  (Read 1865 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: July 20, 2009, 08:48:24 PM »

Hey Nuts -

I've run into a situation where I've needed random rows - now, I'm dealing in dozens of thousands, not tens of millions, but I'm liking what I see.

You may recall we last spoke about giving each row a random key that was indexed - well, I'm doing that and it's damn effective in my application.

I seed the entire database like this:

update listmembers set randkey=RAND() where listid=(x)

This, in and of itself is not that impressive - it takes about 1 second per 50K rows (index on randkey field in force) - which is plenty fast for a lot of applications - but not real time for yours. But, if you seeded your entire database, then simply updated the randkey field with a new RAND() every time it was used, I think you'd get a pretty sweet salad toss.

Just thinkin'.
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #1 on: July 21, 2009, 02:53:36 AM »

Quote
I seed the entire database like this:

update listmembers set randkey=RAND() where listid=(x)

Sorry, what does the (x) mean is this actual SQL or are you implying
to us that you match up the list id in this row...

popcorn.gif

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: July 21, 2009, 10:21:34 AM »

listid is a numeric that indicates which "list" the listmember is part of... sorry it's confusing but it's really immaterial to the example.

lists has an ID
listmembers has a listid pointing to lists.

Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: July 21, 2009, 10:43:22 AM »

cool ok. I probably am going to switch to this. I can update each use, which I do anyway.

I was doing a "datelastused" type of deal, grabbing 50 oldest rows, then randomize those, then use only a handful of them. This created a pretty random set, but still had the tendency towards patterning.

I like your idea better, gonna try that.
thanks!
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: July 21, 2009, 10:48:44 AM »

NW - it's bugged me that we've not come up with something good.

Glad it's sorting out.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!