You are viewing a single thread.
View all comments
26 points

Really enjoyed the read. Thanks for sharing. I’m surprised by the random page implementation.

Usually in a database each record has an integer primary key. The keys would be assigned sequentially as pages are created. Then the “random page” function could select a random integer between zero and the largest page index. If that index isn’t used (because the page was deleted), you could either try again with a new random number or then march up to the next non empty index.

permalink
report
reply
27 points

Marching up to the next non-empty key would skew the distribution—pages preceded by more empty keys would show up more often under “random”.

permalink
report
parent
reply
19 points
*

Fun fact, that concept is used in computer security exploits: https://en.wikipedia.org/wiki/NOP_slide

For choosing an article, it would be better to just pick a new random number.

Although there are probably more efficient ways to pick a random record out of a database. For example, by periodically reindexing, or by sorting extant records by random (if supported by the database).

permalink
report
parent
reply

Technology

!technology@lemmy.ml

Create post

This is the official technology community of Lemmy.ml for all news related to creation and use of technology, and to facilitate civil, meaningful discussion around it.


Ask in DM before posting product reviews or ads. All such posts otherwise are subject to removal.


Rules:

1: All Lemmy rules apply

2: Do not post low effort posts

3: NEVER post naziped*gore stuff

4: Always post article URLs or their archived version URLs as sources, NOT screenshots. Help the blind users.

5: personal rants of Big Tech CEOs like Elon Musk are unwelcome (does not include posts about their companies affecting wide range of people)

6: no advertisement posts unless verified as legitimate and non-exploitative/non-consumerist

7: crypto related posts, unless essential, are disallowed

Community stats

  • 3.9K

    Monthly active users

  • 2.5K

    Posts

  • 40K

    Comments

Community moderators