Random Sutta Getter — r.ReadingFaithfully.org

When I saw the hassle that @mavanyrecords was going through to get a random sutta, I thought that it might be a good coding project.

So, first of all, I want to say that I don’t think that getting a random sutta is the best way to study the suttas. But it seems to be something people want. I even added it into SuttaFriends.org, despite my better judgement.

So, here you have it. A random sutta translated by Bhante Sujato. Includes the first four nikayas and Kp, Dhp, Ud, Iti, Snp, Thag and Thig.

@mavanyrecords’s method wasn’t truly random in the sense that there would be a much higher chance of getting a sutta from the DN or MN than there is with this new thing I created.

The code is basically an extension of the sc.readingfaithfully.org lightweight SuttaCentral interface. I just stripped out all the Pali and removed the previous/next buttons. If you want those things on a random sutta, you can just click the SuttaCentral icon above the translation and it will take you right there.

One of the problems with random suttas this way is that many of the suttas from the SN and AN repetition series are unreadable in the form they are in. ¯\_(ツ)_/¯ Everything has its limits.

I got a list of all the ids by copying all of the suttas I wanted into a singe folder and then did dir > filelist.txt in a Windows command line. I didn’t bother to sort the list since that doesn’t really matter for this project.

As always any feedback is welcome.

And also, as always, much gratitude to Bhante Sujato for making his translations accessible in this way and to all the coders who have helped along the way. And special thanks to @Khemarato.bhikkhu for coaching me in my coding adventure.

11 Likes

That’s brilliant. Are the probabilities for each sutta evenly weighted? One could argue that weighting the MN and DN suttas higher would make sense. Looking quickly at my books, and ignoring the KN, we have, very roughly
DN 500 pages
MN 1200 pages
SN, AN 2000 pages each.
So that makes about 5700 pages, and if you just picked a page at random you’d get a DN sutta about 9% of the time. You probably wouldn’t want it to be that high, but higher than
(number of DN suttas)/(total number of suttas) would probably be good.

5 Likes

Yes, in the sense that there is no weighting at all. And no waiting either! :rofl:

My thinking was that someone clicking the button wouldn’t want to be getting a sutta that might take them 2+ hours to read anyway. And segments aren’t actual pericopes.

So that means that a random segment wouldn’t be much help.

Yeah, there are 4051 “suttas” as they appear on SC. So getting a DN sutta would be ~.8% chance?

But really, I just go back to

Thanks for the feedback, though! I am considering allowing the user to select the books that random suttas would be pulled from. But then it does remove a bit of the randomness since you would be only getting what you wanted.

3 Likes

You could then randomly ignore the users choice to put a bit of randomness back in :wink: - If I coded it, this would probably happen anyway :slight_smile:

Seriously - it might be useful to mention how long (or estimated reading time) of the sutta at the start, then the user could hit the button again if they didn’t have time for a long one.

The icons in the links-area are hard to see.

3 Likes

I love it! Thank you so much venerable @Snowbird :pray:
I second @stu 's comment that the icons in the links-area are hard to see.
Maybe make the background lighter would sort it?
Would it be easy to create a version that goes through translation in other languages?
:bowing_man:

1 Like

You say it’s random, but I get sn42.2 Tāḷapuṭa, which I am choosing to take personally.

Added to SC awesome already!

(very small detail, but this would improve readability IMHO:)

p, li {
    line-height: 1.5;
}

Also the link images at the bottom of the page aren’t very contrasty, black on dark crimson.

2 Likes

Yes… Here’s German for Ayya @sabbamitta’s translations:

https://random-german-sc.netlify.app/
(That’s a temporary link, please don’t publish)

So all I had to do was change this line:

const contentResponse = fetch(`https://suttacentral.net/api/bilarasuttas/${slug}/sujato?lang=en`)

to

const contentResponse = fetch(`https://suttacentral.net/api/bilarasuttas/${slug}/sabbamitta?lang=de`)

Now, it doesn’t really work perfectly. Ayya hasn’t translated all the suttas yet (may she have long life!), so sometimes you hit random and get nothing. But if you just hit it again (and rejoice in Ayya’s merit) then you will eventually come to a translation.

I should be able to put something in the code to try again if it doesn’t find anything. Just wanted to show off how easy it was to do what you asked.

Now, it only works with Bilara translations. There is no API for the others. I guess once I fixed that no-result problem I could just have a dropdown to select the language.

Thank you, Bhante. I was also thinking about increasing letter spacing for the same reason.

And yes, the icons are just temporary. I have to remake them all in a new colour, so it takes a while.

I’m torn. I love the idea, but I also don’t want to clutter the page any more than it already is. You can kind of tell how long a sutta is by looking at the scroll bar. Why don’t you open up an issue on Github (nudge, nudge).

1 Like

Oh, sweet! :heart:

There’s only a little problem: it doesn’t actually give you a Sutta.

(And the explaning text should of course be in German, but that’s easy to solve. I’ll translate it for you.)

Ah, okay, I only read that later (was too fast in wanting to try it out!)—I had to press 5 times to get a Sutta, which isn’t quite representative. According to the Bilara progress counter, there should be translations for about 48% of the project I want to translate.

Would this list be of help? It’s updated regularly.

Nooooooo!

A man who would letterspace lower case would steal sheep,
Frederic Goudy (yes, the Goudy of the font!)

Font designers carefully design fonts with the correct letterspacing. You’re using source serif pro, which is beautiful and took many years of careful design by a leading professional. Don’t spit in his soup!

Generally it looks great, you don’t need much.

The only other suggestion would be to avoid faux-bold in headings. Either serve a bold font, or specify normal weight:

h1,h2,h3,h4,h5,h6{
    font-weight: normal;
}
1 Like

Well, not with the way this code works. It’s not reasonable to have to keep updating with new texts. So I probably wouldn’t make a language available unless it was mostly a good chunk there.

Hmm. It is pulling from everything that Bhante Sujato has translated, so that’s really what it should be measured against.

The German language version was really just an experiment. At this point I wasn’t planning on publishing it. But if you wanted to I would be happy to complete a version for German.

1 Like

Hmm … well, it probably wouldn’t. It only includes languages that have narrator voices in Voice, and there are a few more languages with segmented translations on SC meanwhile. Sorry … :person_shrugging:

Well, there are weekly updates and additions for the German translations. If your code can’t keep up with changes, a German version would very quickly just have outdated texts. It was a nice experiment, but no, in this case rather don’t put any further effort into a German version. But thanks anyway! :heart: :smiley:

1 Like

css filter is a quick fix - this is a cool tool: https://codepen.io/sosuke/pen/Pjoqqp

:rofl:

Ha! That’s what I’m working on right now. But the icons I have there now are black, so filter isn’t doing me much good.

Well, my idea was to have it just check to see if the chosen sutta existed and if it didn’t, then it would keep looking for one. So it might take a second to find one, but then the code would never be out of date. And if you already knew the texts that you were never planning on translating, then I could remove them from your German version. That would reduce the number of blank hits.

2 Likes

So that means, if it finds a Sutta, that would automatically be the latest version. Got it.

I am planning to translate the same Suttas that Bhante Sujato has translated. Of those, about 48% are done.

3 Likes

Fantastic. If possible, feel free to implement one for portuguese translations in Bilara as well. They are much fewer than Ayya’s and the legacy.

:anjal:

2 Likes

OK! So I fixed the icons at the bottom.

I’m also experimenting with using a sanserif font instead. Ven, @Pasanna, feel free to critique! I’m guessing you won’t be crazy about the dark background. It passes the contrast test, though.

From what a quick glance showed, there appear to be less than 200. Is that correct?

2 Likes

Hmmm… Maybe needs a loading state? It took ~5 seconds to load for me after hitting the button. Enough time that I thought it was broken.

I happened to get a DN Sutta in German, and noticed that the sub-titles are hard to see:

You can only suspect that something could be there. Only highlighting it makes it visible:

(Maybe that’s already resolved for the English version, but just in case it is not …)

Ah, great!

That’s the problem with a testing environment that only returns DN suttas .8% of the time! Just a few minutes ago I realized that lists are incorrectly coloured too.

2 Likes