Interesting problem. In a JavaScript
, all the entries in the library are read into an array (like a list, but numbered 0 to maximim - 1 instead of 1 to maximum). If you could generate a random integer such that 0 <= number < # of entries, you could do it. So, how to do that? Well, as you can read at...
..., there is a method (a function) that will return a real number between 0 & 1. So, to scale that to the number of entries in your library and simultaneously make the number an integer (so you can use it to select an entry), you can use a function like this in your code...
function getRandomInteger(max) {
return Math.floor(Math.random() * max);
}
So, start with that and then write the rest of your script...
let entries = lib().entries();
let numberOfEntries = entries.length;
let selection =
getRandomInteger(numberOfEntries);
let e = entries[selection];
// Put code to show this entry here
So, you'd bring up the entries list for your Music library and press the action button (looks like a YouTube Play button near the top of the screen).
But, to bring that entry up on the screen, there used to be a function called show(e) that would display the entry in an entry view card, but some of us have found that that function no longer exists or works. It did exist and work back when I documented it in the wiki. We'd need to ask the developer about that...
Sup...@MementoDatabase.com
So, we've identified the intended entry, but I don't know how to select that entry as the current entry.
So, developer, we have the entry in the variable e. Now how do we make that be the current entry and show it? Does show(e) or lib().show(e) exist? How does it work? It apparently no longer works as documented in the wiki.