Genuinely Random Link Generator

By Venryx Venryx

Description

Up until now, there were two ways to create random links:

  • Display all of the pages in a mini-block, filled with tiny, black rectangles which link to each of the pages. Because they're so small and lack identification, the person ends up navigating to an essentially random page.
  • Have a link to the page 'random', where you add the ListPages module to sort the pages and redirect to the first of the list. This is genuinely random, but the 'randomly-sorted list' is only re-shuffled every minute, meaning that you can't keep clicking it to see more randomly.

Based on the second method, I've figured out a way to combine ListPages and Javascript to provide genuine randomness without having to wait for the ListPages module to re-shuffle.

There are two versions of this method. The first is easy to implement, but requires two page redirections. The second is harder to implement and involves the use of i-frames, but cuts the process down to only one redirection.

Instructions

Simple Version (2 page redirects)

1. Create a link in the Sidebar to the page 'nav:random'.

2. Follow the link, and create the page 'nav:random' with this code:

[[html]]
<html>
<body>
 <script type="text/javascript">
 window.parent.location.replace(document.URL.substring(0, document.URL.indexOf("/local")) + "/nav:random-redirect/offset/" + Math.random());
 </script>
</body>
</html>
[[/html]]

Note: After saving the page above, you'll be redirected to 'nav:random-redirect'.

3. After being redirected, create the page 'nav:random-redirect' with this code:

[[module ListPages category="_default" order="random" limit="1" offset="@URL|0"]]
[[iframe http://snippets.wdfiles.com/local--code/code:iframe-redirect#%%link%% frameborder="0" width="1" height="1"]]
[[/module]]

Now you've got a random-page link on your sidebar that can clicked as frequently as you like without caching its results.

(Note: If you need to edit or delete the pages, add '/norender/true' to the end of the page address.)

Complex Version (1 page redirect)

1. In the Sidebar, add the line below: (replacing "<WEBSITE ADDRESS>" with the address of your website, e.g. "http://venryx.wikidot.com", and replacing "17px" with an appropriate height for the link we're about to put on your sidebar.)

[[iframe <WEBSITE ADDRESS>/local--code/nav:random transparency="true" frameborder="0" height="17px"]]

2. Create the page 'nav:random' with this code: (replacing the CSS between the "<style>" tags with whatever gets the link to look like the others on your website's sidebar. (you may need to "Save & Continue" the page and view the sidebar on another tab to get the link to look right, and you may need to look through your website's CSS file as well.))

[[module CSS]]
.code {border: 0; background-color: transparent; display: none;}
[[/module]]
[[code type="html"]]
 <style type="text/css" id="internal-style">
 @import url(http://d3g0gp89917ko0.cloudfront.net/v--c4924039f145/common--theme/base/css/style.css);
 a {color: #444;text-decoration: none;}
 a:hover {color: #76ae45;text-decoration: none;background-color: transparent;}
 body {font: 13px/1.3em "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;}
 </style>
 <script type="text/javascript">
 if (window.location == window.parent.location)
 clicked();
 function clicked()
 {
 window.parent.location.replace(document.URL.substring(0, document.URL.indexOf("/local")) + "/nav:random/offset/" + Math.random());
 }
 </script>
 <a href="" onclick="clicked()">Random</a>
[[/code]]
[[module ListPages category="_default" order="random" limit="1" offset="@URL|0"]]
[[iframe http://snippets.wdfiles.com/local--code/code:iframe-redirect#%%link%% frameborder="0" width="1" height="1"]]
[[/module]]

Now you've got a random-page link on your sidebar that can clicked as frequently as you like without caching its results.

(Note: If you need to edit or delete the pages, add '/norender/true' to the end of the page address.)

In action

The complex version: http://gustrength.com


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by Venryx


Rate this solution

If you think this solution is useful — rate it up!

rating: +6
(account deleted) 30 Jun 2014 08:17

Yes. This is much better than the default "wait 60 some second" thing.
It takes a second to load a random page, but it works well.

by (account deleted), 30 Jun 2014 08:17
Helmut_pdorf Helmut_pdorf 01 Jun 2012 05:26

Venryx is/was the author of the first tries .
But for such issues i would like to have one or more backups on our backupstorage ( not yet any bakup stored) - but this makes all the source available for all users…


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 01 Jun 2012 05:26
GoVegan GoVegan 31 May 2012 22:02

Is there a reason you deleted and recreated this snippet?

by GoVegan GoVegan , 31 May 2012 22:02
page revision: 1, last edited: 31 May 2012 16:28
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /