- Sloth Bytes
- Posts
- 🦥 Random isn’t “Random”
🦥 Random isn’t “Random”

Hello friends!
Welcome to this week’s Sloth Bytes. I hope you had a great week.

Dex AI Scrapes the internet and sets up interviews for you
Dex is a conversational AI and career matchmaker that works on behalf of each person. You spend 15-20 minutes on the phone with him, talking about your experience, your ambitions and your non-negotiables.
Dex then scans thousands of roles and companies to identify the most interesting and compatible opportunities.
Once we’ve found a match, Dex connects you to hiring managers and even helps you prep for interviews.
Thousands of exceptional engineers have already signed up and we’re partnered with many of the UK’s leading Start-ups, Scale-ups, hedge funds and tech companies.
Don’t waste another day at a job you hate. Speak with Dex today.
Go from AI overwhelmed to AI savvy professional
AI will eliminate 300 million jobs in the next 5 years.
Yours doesn't have to be one of them.
Here's how to future-proof your career:
Join the Superhuman AI newsletter - read by 1M+ professionals
Learn AI skills in 3 mins a day
Become the AI expert on your team

Why Random isn’t “Random”

A few years ago, I was in a final-round technical interview.
Fun little zoom call. Multiple interviewers. My hands were sweating like crazy.
After finishing all the normal interview problems we had some extra time.
So they asked me a fun bonus question:
“How would you write a program to randomly shuffle a deck of cards?”
Easy enough, right? I asked if I can use the random package and they said sure.
Now in my head I thought “Wow this is way easier than the other questions.”
The solution basically looks like this with the random package.
#Simplified version - shuffling numbers in an array
import random
deck = [1,2,3,4]
#Yep the random package has a shuffle method.
random.shuffle(deck)
Boom. Done.
At this point I felt pretty confident, but then one interviewer hit me with this question:
“How do you know if that package is truly shuffling them random?”
And that’s where I froze. Because I had no idea.
Is random actually random?
Well… Computers Can’t Do “True” Random
Here’s the thing: computers are deterministic machines.
If you give them the same input, you’ll always get the same output.
There’s no “surprise” in them.
So by default, they can’t create real randomness on their own.
(There are ways to get closer to “true” randomness though… we’ll get to that later)
What is the computer doing then?
When you ask your computer for randomness, it doesn’t pull chaos out of thin air. Instead, it uses a pseudorandom number generator (PRNG).
These are algorithms that produces numbers that look random but are actually predictable if you know the starting point which is called the seed.
PRNGs in simple terms
PRNGs usually consist of two parts:
The seed
A math algorithm that spits out numbers.
The seed is the starting point and the math algorithm uses that seed to generate a sequence of numbers.
Why do we need a seed?
To reproduce the “random” result. Weird, I know.
Same seed → you always get the exact same sequence of numbers.
Different seed → you get a different sequence.
Example you can try
import random
random.seed(42)
print([random.randint(1, 10) for _ in range(5)])
The output you should get is [2, 1, 5, 4, 4].
No matter how many times you run it, you’ll always get those numbers.
Why is this useful?
Because reproducibility matters:
In ML experiments, you want the same “random split” of data.
In debugging, you want to replay the same test run.
In games, you want to recreate the same world from a seed (Minecraft)
So “random” in this case isn’t true randomness. It’s just math following rules.
Where Do Seeds Come From?
Okay, so if PRNGs need seeds, where do those come from?
Most languages/libraries default to seeding from something unpredictable like:
The current system time in nanoseconds
CPU state
Operating system entropy pools (hardware events like mouse movement, disk noise, or network jitter)
This makes it much harder to predict the seed, but still not truly random since it only generates it once.
♠️ Back to the Deck Shuffle
Now we only covered how the “random” part works, but how does the shuffle work?
Most programming language’s random package under the hood uses an algorithm called the Fisher-Yates shuffle.
Here’s the implementation in Python (thanks wikipedia):
def shuffle(numbers: list[int]) -> list[int]:
for i in range(len(numbers) - 1, 0, -1):
#IMPORTANT PART!
j = random.randint(0, i)
numbers[i], numbers[j] = numbers[j], numbers[i]
return numbers
You see that random.randomint(0,i)
That is what’s making this implementation possible.
The randomness of that shuffle is only as good as the random numbers it generates.
If the PRNG is weak, patterns can emerge.
And that means it’s not that “random.”
🔐 Crypto-Grade Randomness
WAIT A MINUTE… If patterns can exist, doesn’t that mean encryptions and random password generators are not that secure?
Couldn’t attackers could guess the seed and reproduce the sequence.
Well… yes (it would still take some work though)
But don’t worry, modern systems provide cryptographically secure PRNGs (CSPRNGs).
These pull from operating system entropy pools and use algorithms that are designed to be unpredictable.
Example
# Python's secure randomness
import secrets
print(secrets.token_hex(16))
These are what you’d use for things like passwords, API keys, or cryptography.
Even someone with full knowledge of the algorithm still can’t predict the outputs.
They literally point cameras at the bubbling patterns and feed that noise into their systems to help with their “random” encryptions.

These lamps right here are helping you with your SSL/TLS encryptions
Takeaway
That interviewer asked a really good question. I don’t know if this was the answer they were looking for, but still a good question.
If I could go back to that interview, I’d probably say something like this:
“No it’s not truly random, because the random package uses a pseudorandom number generator. If you figure out the seed, you’ll get the same result. If I wanted to improve the randomness, I’d use a cryptographic randomness source like the secrets
package, since that can’t be predicted or replayed.
If I said that, I probably would’ve gotten the job…
But hey, maybe it’ll help you with one.



Thanks to everyone who submitted!
grcc492, Melvis-07, Yeshua235 , AspenTheRoyal, gcavelier (used a crate/package to handle it. Practical. I respect it), jsjasee, NeoScripter, and Suji-droid!
A lot of you solved it with dfs and bfs great job!
Keyword Cipher
A Keyword Cipher replaces each letter of a message with a letter from a shifted alphabet built using a keyword.
Start with the keyword.
Add the remaining letters of the alphabet (A–Z) in order, skipping any that already appeared in the keyword.
Example keyword:
"KEYWORD"
Cipher alphabet:
KEYWORDABCFGHIJLMNPQSTUVXZ
Encrypt by replacing each letter in the message with the letter at the same position in the cipher alphabet.
Plain alphabet:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher alphabet:
KEYWORDABCFGHIJLMNPQSTUVXZ
Write a function that takes a key
and a message
, and returns the encrypted message.
Examples
keyword_cipher("keyword", "abchij")
Output = "keyabc"
keyword_cipher("purplepineapple", "abc")
output = "pur"
keyword_cipher("mubashir", "edabit")
output = "samucq"
keyword_cipher("etaoinshrdlucmfwypvbgkjqxz", "abc")
Output = "eta"
keyword_cipher("etaoinshrdlucmfwypvbgkjqxz", "xyz")
Output = "qxz"
keyword_cipher("etaoinshrdlucmfwypvbgkjqxz", "aeiou")
Output = "eirfg"
How To Submit Answers
Reply with
A link to your solution (github, twitter, personal blog, portfolio, replit, etc)
or if you’re on the web version leave a comment!
If you want to be mentioned here, I’d prefer if you sent a GitHub link or Replit!
That’s all from me!
Have a great week, be safe, make good choices, and have fun coding.
If I made a mistake or you have any questions, feel free to comment below or reply to the email!
See you all next week.
What'd you think of today's email? |
Want to advertise in Sloth Bytes?
If your company is interested in reaching an audience of developers and programming enthusiasts, you may want to advertise with us here.
Reply