4

The "Unofficial" Random Rant Feature is Here.

Just visit https://is.gd/rants

Source: https://gist.github.com/theabbie/...

Inspired from these issues
https://github.com/devRant/devRant/...
https://github.com/devRant/devRant/...
https://github.com/devRant/devRant/...

If it breaks, just let me know here.

Comments
  • 1
  • 9
    No need for this. It's part of the API.
  • 1
    @AlgoRythm didn't know that, it did not require any effort though
  • 7
    @theabbie I just read the source code. You really load the entire database of every rant each time a request comes through? Just to pick one out of the bunch and then discard the huge dataset? That must be why it took so long for mine to load.
  • 1
    Okay guys, it's the part of the API, my bad, didn't notice, my version didn't use the API, whatever, might be fun to try this one.
  • 1
    @theabbie it's also an IOS shortcut... although I haven't shared the shortcut source.
  • 0
    @AlgoRythm It is preloaded, and saved, I collected it while creating the leaderboard, I might just update it regularly with new rants,

    Anyways, I can modify it to use the API instead
  • 0
    @C0D4 Just consider this as an alternate version then
  • 3
    @theabbie what would the point of modifying it to use the API be? That's just an unnecessary step.

    And you load all the rants via a HTTP request to https://del.dog/raw/rants

    Then you split them. You do, in fact, import the entire database each time someone makes a request.
  • 1
    @AlgoRythm The API returns an id, it would just redirect to it, I know it's pointless, I am just trying to cover up my stupidity.

    Also, yes it's fetching 200k+ rant IDs for every request, but DevRant is safe from this abuse,

    Also, it's truly random, completely unbiased, don't know about how API does it.
  • 3
    @theabbie turn it into learning.

    Lead the database ONCE.

    Look at node.js's cryptography library and learn how to use more true randomness. Math.random is called pseudo-random because it is actually not very random at all.

    Here's another exercise: see how random works in c. You can call the random function, it will always give you the same numbers if you don't seed it first. Most people just seed it with the current system time.

    JavaScript random does the same, but the browser seeds it for you. This should show you that the random function is actually rather predictable, which is why the crypto libraries exist.

    Have fun.
  • 0
    @AlgoRythm Suppose this API didn't exist, do you know a pattern from which rant IDs are generated? so that we can efficiently find Random Rant rather than fetching all rants.
  • 1
    @theabbie There's no pattern. The ID is a shared key between users, comments, rants, and whatever else devRant assigns an ID.

    1 could be a user
    2 could be a rant
    3 could be a comment.

    That, plus the fact that content can be permanently deleted, is why you see gaps in the IDs.
  • 0
    @AlgoRythm didn't understand what you meant by "Lead the database ONCE"

    also, by truly random, I mean, what is generated by the inbuilt function, and any random number generated by using any number of seeds will not be "truly" random, it can only be generated by special hardware which uses entropy.

    so, the pseudo-random number here is fine as this is not used for cryptography or security purposes.
  • 2
    @theabbie typo. I'm on my phone. I meant load.

    Do it outside your HTTP handler. So before the "app.get" bit. Very easy way to just grab the data one time.

    Yeah, math.random is perfectly fine and I would use it too. But if you wanted to turn this redundant project into something fun, you could provide a "more random" experience and learn the node crypto library in the process.
  • 1
    @AlgoRythm But ID's have an increasing order based on chronology, are those gaps intentionally inserted? because, they can't be just deleted rants, and, ate those gaps random?
  • 0
    @theabbie it's possible they have random gaps but I doubt it.

    Consider this scenario:

    -A rant is posted. ID 1000 for simplicity.
    -Next, a comment is posted. ID 1001
    -A new user registers. ID 1002
    -A discussion is happening. 100 comments are posted. ID is now 1102
    -Finally another rant is posted. ID 1103
  • 0
    @AlgoRythm It's a lambda function, ie. server only runs when called, so, loading anything in advance is not in my hand. also, it does not have a dedicated filesystem, so, I can't save it on server.

    Also, though predictable, Math.random successfully generates "conventionally" good random rumbers, ie. a coin tossing using Math.random will work good.

    Don't know how crypto works, but, without special hardware, random numbers will not be truly random. Using 100s of seeds might make it highly difficult to predict, but, mathematically valid random numbers needs special hardware.
  • 1
    @AlgoRythm Why did they use same length IDs for everything, that means, every number in those gaps is something, either a comment or a user.
  • 0
    @C0D4 I am a "smart" Android user, still, you might consider sharing it for other folks.
  • 1
    @theabbie it's a way that they can deter scraping slightly while still using a numerical ID rather than a UUID
  • 1
    @theabbie I still need to get it to work safely with images, but text wise it's stable.
  • 0
    @AlgoRythm It's pretty easy to scrape all rants from the sitemap,

    https://devrant.com/static/devrant/...

    If I had created it, I would have used same length but user IDs would start with "u" like "u0000", "u1111", comment IDs would be related to parent rant and start with "c" and rants with "r".
  • 0
    @C0D4 You have created it or it is part of official app? or, you have created it for official app?
  • 1
    @theabbie
    Shortcuts is an official Apple app

    https://support.apple.com/en-au/...

    But you can create your own actions / automations with a nocode interface.
    It is limited and a pain in the ass, but has potential. You can also execute python externally through a paid app,
    Pythonista, that integrates with it which improves the scope of what you can / can't do.

    But out of the box, it's good enough with a fair amount of elbow grease.
  • 1
    @C0D4 oh, it's like IFTTT, also, if it's in API why isn't there a button to load random Rant?
  • 0
    @theabbie actually, yea it is a bit like IFTTT, just native.

    As for the api, maybe it's missed feature for the app, or... as the endpoint suggests, a surprise 🙃
    Honestly though, who knows what dfox was thinking all those years ago, I'm sure there was a late night beer and an idea involved though.
  • 0
    @C0D4 There were Feature Requests on Github where he said it will be added, it's of 2017, maybe, he forgot to add it to official release.
  • 0
    Hey Everyone, This one uses Official API, might be faster,

    https://is.gd/newrants
  • 1
    @theabbie Your comment about random: Yes, as CSPRNG (cryptographically secure peseudo random generstor) isn't "truly" random.
    But it's good enough for any purpose. For details how those are created look at https://schneier.com/wp-content/... (complete design) and for general constructions https://csrc.nist.gov/publications/... (building blocks, see the linked 800-90b and c for other components).
  • 0
    @sbiewald Math.random is fine for this purpose, will check them out though
Add Comment