how does “random” work?

preview_player
Показать описание
You've probably heard of rand( ). You've probably even used it in your code. But unfortunately, you've probably used it wrong. In this video, I talk about the glibc implementation of a random number generator, rand, why it's bad, and what other options there are for RNGs.

🏫 COURSES 🏫

🔥🔥🔥 SOCIALS 🔥🔥🔥
Рекомендации по теме
Комментарии
Автор

teehee I got a little excited with my second camera. 😇 THANKS FOR WATHCING<3

LowLevelLearning
Автор

PSEUDOrandom, that prefix is important

hectorjuncal
Автор

Given a sequence of pseudo random numbers (no gaps) you can use a logic solver like z3 to calculate the internal pRNG state, allowing you to predict future outputs.
This even works when the generated numbers are not directly used but truncated in some way (e.g. conversion to hex/base64 representation and cutoff). This just increases compute time for the logic solver.

RegrinderAlert
Автор

While we should always use a secure RNG function for code that demands security, there is still a use for pseudorandom numbers! A known seed is nice to debug things in games, where it is expected to be infeasible for players to predict the outcome, but something reproducible just by providing a seed and replay would help. We use it for races in randomizer hacks and Minecraft so that the players can't predict what the game state will be, but can vet it independently and make sure all participants are playing the same game.

saxxonpike
Автор

My favorite seed for rand() is 42. When you use that seed it returns a string that says "The answer to life, the universe and everything".

anon_y_mousse
Автор

Great video. However, it is also worth mentioning that many modern microcontrollers have TRNGs (true random number generators). These are based on things like static, noise in semiconductors, etc. I would love to see your take on these.

knightflyer
Автор

My favorite computing thread to pull on here is:
- LCGs are great, so the ease of implementation makes it a good teaching method ("write your own")
- LCGs can be put into a tree-like structure. This is useful in parallel computing (where one random seed creates the seeds for 10 different threads), but a more fun example might be generating procedural plants in a video game: Say you use the seed to create 1000 randomly generated plants, each using 10 random number calls each, and you are trying to store as little data as possible (so, at the start it's just the seed). Now you want to modify the 10th plant, but in doing so you've used 11 random number calls. Now the first 9 plants are the same, the 10th has been modified, but the other 990 are all modified too because the random numbers requested have all been shifted by 1! If instead you use an LCG tree, you can basically make the RNG state local to each object instead of global to the whole program.
- I might be getting this story slightly wrong, but Bell Labs made a special purpose computer back in the 80's to simulate a particular physical system (the spin glass), but they built in a linear shift register RNG into the hardware. They still got useful results from the computer, but the poor quality RNG made the results pretty bad! So their promising hopes and dreams of scaling up the special purpose computer were dashed. But I need to check my primary sources here, I believe the machine I'm thinking of is described in "Fast special purpose computer for Monte Carlo simulations in statistical physics" and they do actually describe an RNG algorithm in that paper.

davidmoore
Автор

Most code initializes the seed with the timer only once. If you get a sequence of pseudo-random numbers you can solve these modular equations and recover the seed. Once you know the seed you know the whole sequence.

jcamargo
Автор

This video's topic was so random 🥁

davidgomez
Автор

Ehh I’m not too worried about the cryptographic security of the shuffle function in my music player app lol

TagetesAlkesta
Автор

Since your channel is called "Low Level Learning", I would have expected you to talk about true random number instructions like rdrand 😅 and a sample where you use it.

AntonioNoack
Автор

I learned this the hard way when using it for an MPI application, getting the same number on different processes running in parallel 😂

Mane
Автор

Assuming you have access and 'good enough' resolution of your processor's temperature reading, I think you can combine time + temp read for your seed value :D

juskim
Автор

I just wanna say that this video and "Why rust is being used for evil" are putting us in infinite loop if we follow that recommended video. :D good vids!

RootsterAnon
Автор

Really good video explaining the foundations of why such customary stuff is written

rusty
Автор

I mistakenly assumed the newer random() implementations read from the system random number source device. In Java, I ran into some issues with performance because in Java they did reach out to the device in AIX and Linux and had performance differences.

cliffmathew
Автор

I thought it was common knowledge that rand() isn't actually a true RNG and it must be initialised with a seed like the current timestamp each time it's used, no?

evangelosraptis
Автор

You can actually combine a standard PRNG and a either a cryptographic hash function or a block cipher to make a (admittedly fairly simple and not too secure) CSPRNG. Just either hash the output of your RRNG or encrypt it using a randomly generated key to get a cryptographically secure random number

TheyCallMeHacked
Автор

This channel is really becoming my new favorite, your videos are great!

thebillpepper
Автор

I enjoyed this video on the use of rand() and RNG (Random Number Generation) in coding! It's fascinating to see how these techniques can be applied in various scenarios, from simple games to complex simulations. The explanation of different RNG algorithms and their strengths and weaknesses was particularly informative. It's always great to be reminded of the importance of high-quality randomness for security and statistical applications. Thanks for sharing this educational content!

szilagyimiklos