How to implement random article pointer in JavaScript

I cannot do this in the WordPress.com platform because it does not let me execute JavaScript. But, in other platforms you can do this:

<html>
<body>

<script>
    var randURLs = [
        "https://sureshemre.wordpress.com/2013/12/08/electronic-edition-of-the-works-of-p-r-sarkar-shrii-shrii-anandamurti/",
        "https://sureshemre.wordpress.com/2011/12/07/ananda-sutram/",
	"https://sureshemre.wordpress.com/2020/06/26/ignoring-agency-is-ignorance/",
	"https://sureshemre.wordpress.com/2020/06/10/what-percentage-of-scientists-are-atheists/",
	"https://sureshemre.wordpress.com/2020/05/30/concept-of-gauge-invariance/",
	"https://sureshemre.wordpress.com/like-60-seconds/",
	"https://sureshemre.wordpress.com/2020/04/24/howard-h-pattee-and-the-physics-of-symbols/",
	"https://sureshemre.wordpress.com/2020/03/28/on-the-transformation-of-neutrino-into-electron/",
	"https://sureshemre.wordpress.com/2020/03/24/conservation-laws-of-particle-interactions/",
	"https://sureshemre.wordpress.com/2020/01/24/my-obsession-with-the-pageview-count/",
	"https://sureshemre.wordpress.com/2019/07/27/on-the-emergence-of-space-and-time/"
    ];

    var randURL = Math.floor(Math.random() * randURLs.length);
    window.open(randURLs[randURL],'_self');
</script>

</body>
</html>

In other words, you prepare a list of URLs and point to one of them using the Math.random() function of JavaScript.

For demonstration you can go to this link

https://sites.google.com/view/sureshemre/Home

Every time you refresh that webpage or click on the “random_article” link that is placed on the left hand side of that webpage you will get a random article from this blog. The same article may come up few times in a row but in general you will get a new article each time. The number of articles in the “random” selection is limited. The list will grow as I add more.

This entry was posted in computer science. Bookmark the permalink.