It’s the season of stumbling:
StumbleUpon, in its most recent toolbar, introduced a new feature called StumbleThru, which allows users to stumble through pages on a specific web site.
Google introduced a recommendations button that you can add to the Google toolbar. The button looks like a pair of dice. Every time you click on the dice, you will be taken to a site that may be interesting to you based on your past searches.
Matt Mullenweg introduced a new WordPress plugin, Random Redirect, which is a special URL that, when clicked, will redirect to a random post on your blog, in a StumbleUpon-like fashion.
I have activated the Random Redirect plugin on my blog. Every time you click on this link you will be served a random post from the list of all my previous posts. You can also find this link on the blog’s top menu bar.
Out of curiosity, I took a look at the code behind the Random Redirect plugin, and amazingly, it is very short and simple. Here it is, the whole plugin:
function matt_random_redirect() {
global $wpdb;
$random_id = $wpdb->get_var("
SELECT ID
FROM $wpdb->posts
WHERE post_type = 'post'
AND post_password = ''
AND post_status = 'publish'
ORDER BY RAND() LIMIT 1");
wp_redirect( get_permalink( $random_id ) );
exit;
}
if ( isset( $_GET['random'] ) )
add_action( 'template_redirect', 'matt_random_redirect' );
Notice the ORDER BY RAND(), this reminds me of one of my earlier posts: ORDER BY no order. Basically, you can do the same in Oracle: ORDER BY dbms_random.random.
A while ago I blogged about how you could use the rpad function to generate a string of any length. Kristian suggested another way to do it, using the dbms_random.string function. In this post, I will write about what I have noticed when using the two approaches. (more…)
While reading this page, I stumbled upon a trick (by Tom Kyte) to generate an alphanumeric character string of any length using the Oracle SQL function RPAD. The emphasis here is on the length of the string, not its content. Let’s say you want to generate a 10 character string, you can easily do it like this: (more…)
Back in the old days when DBMS_RANDOM did not exist ( pre Oracle 8 ), How did Oracle developers generate random numbers? Now I know. (more…)
If you want your result set ordered by something, you better use the ORDER BY clause. If you don’t, there is no guarantee that the rows from the query will be ordered in any way. Fine, you may already know that. But, what about if you want to make sure that the rows from a query are returned in no specific order, i.e. in a random order. Here is how you can do it: (more…)
If you’ve ever wanted to generate a random password, a random number, or just a random string, dbms_random is here to help. Here is an example of the different uses of this useful package: (more…)