Randomness is calculated - Linear Congruential Generators Explained

  Рет қаралды 10,970

BearTheCoder

BearTheCoder

Күн бұрын

In my last video I began my exploration into Perlin Noise because of Minecraft and my unhealthy need to do something with graphics. Well, I completely abandoned that this week and did nothing but math.
The Linear Congruential Generator, often referred to as LCG, is an equation that computers use in order to create "random" numbers. The result of this equation is calculated often by using prime numbers and a mathematical operator called a modulo. The resulting number from the LCG is our "random" number. This number is then fed back into the equation creating a chain of random numbers until the equation ultimately loop. Since the 50's mathematicians have been searching for the right combination of numbers to create the ultimate LCG...this is not that.
There are a couple resources that might help you on your journey if you are attempting to write your own LCG or join the fight to create the best LCG you can.
Good Luck.
"Tables of Linear Congruential Generators of Different Sizes and Good Lattice Structure" - by Pierre L'ecuyer:
www.ams.org/jo...
Linear Congruential Generator Wiki:
en.wikipedia.o...
"Random Number Generators" (Hull-Dobell Theorem) - by Hull, T.E. and A.R. Dobell:
dspace.library...
My Last Video on Perlin Noise:
• [Explained] Perlin Noi...

Пікірлер: 50
@benbalaj1732
@benbalaj1732 Жыл бұрын
I wasnt expecting such a tastefully comedic and thorough explanation. I tip my hat you my good sir
@JZsBFF
@JZsBFF 3 ай бұрын
Beard, jokes, no tie, glasses,... Except for the beer; my kind of teacher. I wish you were in front of the class in sat in 50 years ago.
@arkadymarchenko1516
@arkadymarchenko1516 8 ай бұрын
I loved this video! It was super useful for me to understand LCG and your video style is through the roof! I see you haven't made videos recently but I would absolutely watch more of your stuff
@BearTheCoder
@BearTheCoder 8 ай бұрын
Thank you for the love! Not that I don't want to make videos, just haven't figured out how to navigate the coding and tutorial space with AI coming around. Got to decide if there is still a need for videos like these.
@Sydney_Anuyah
@Sydney_Anuyah 2 жыл бұрын
This is so awesome! I have never heard of LCGs until class today! And I got a far better understanding
@vedanthkuchibhotla285
@vedanthkuchibhotla285 2 жыл бұрын
By far the best video on LCG in YT. Top notch editing a bonus !
@mhattaaldinor7548
@mhattaaldinor7548 4 ай бұрын
This is great and fun explanation of this algorithm, thanks a lot man
@nekaamunoz
@nekaamunoz 2 жыл бұрын
Great video!! I love your editing. Keep it up! :)
@BearTheCoder
@BearTheCoder 2 жыл бұрын
TYSM!
@malvis8737
@malvis8737 Жыл бұрын
what is the difference in between using the random numbers generated by the libraries in the differnets programing languages instead of using the congruential generator? which one is better and why ?.
@BearTheCoder
@BearTheCoder Жыл бұрын
en.m.wikipedia.org/wiki/List_of_random_number_generators
@BearTheCoder
@BearTheCoder Жыл бұрын
“Randomness” is an arbitrary and unmeasurable value so it’s impossible to determine quality or difference based on that value. But, the period, or looping period is measurable and that is the primary difference.
@malvis8737
@malvis8737 Жыл бұрын
@@BearTheCoder thank you for your answer .
@lucaswoon6118
@lucaswoon6118 Жыл бұрын
This video was very nicely edit and informational :] thanks a lot
@salah777
@salah777 Жыл бұрын
thanks for this great content I hope you get more subscribers
@BearTheCoder
@BearTheCoder Жыл бұрын
1 at a time. Thank you!
@nkumarasena1409
@nkumarasena1409 Жыл бұрын
woah tommorow is my crypto exam and this helps me lot mate thankz:D
@Cutest1TheGame
@Cutest1TheGame 7 ай бұрын
@6:11. I appreciate the time and effort you put into this. It really does take a long time to direct and edit a video.
@PvblivsAelivs
@PvblivsAelivs 2 жыл бұрын
The second "ridiculous" method is also found in _The Art of Programming_ The general idea is to use a modulus that is a large prime or a large power of 2. If you use a large prime, 'c' should be zero and 'a' should be a primitive root of that prime. It's a very interesting topic. But I suspect I have gone deeper into it than you have. And that's okay. Most people just want a black box that spits out "random" numbers and are more than happy to use library routines to do it.
@Cutest1TheGame
@Cutest1TheGame 7 ай бұрын
Here’s another comment: I love the title of your video. It’s one of two reasons I picked yours over the other video which showed up in spot 1 when I searched for “linear congruential generator”. The second reason is because you use colorful illustrations in your thumbnail. The other video looked dry.
@mithuncoorg65
@mithuncoorg65 Жыл бұрын
How does number 8 comes after 5,7,7 in linear method please explain.
@jonasblom6177
@jonasblom6177 2 жыл бұрын
Great vid mate! Commenting for the youtube algorithm
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank for that! Appreciate the love!
@adssib04
@adssib04 Жыл бұрын
Goodddam it ur awesome bro , keep it up ur videos are soo good GL
@JamesSarantidis
@JamesSarantidis 9 ай бұрын
How does one calculate the efficiency of the sequence produced by an LCG? In the video the example was about 40%. How does one derive that?
@BearTheCoder
@BearTheCoder 9 ай бұрын
So, LCGs have a maximum amount of number sit can produce because you are using a modulo. If the modulo is 10 the maximum amount of random numbers it can produce is 10. But LCGs tend to loop. So if an LCG produces a 6 then 4 then 3 then 7 then 6, you only got 4 numbers out of the possible 10, so 40% efficiency.
@JamesSarantidis
@JamesSarantidis 9 ай бұрын
@@BearTheCoder Ah, I see. Thank you both for the explanation and the video :)
@estevaoyt
@estevaoyt Жыл бұрын
This is so goood! Thank you!
@Jozef13H99
@Jozef13H99 2 жыл бұрын
Also commenting for the algorithm. This was a fun watch ^_^
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you!!
@DalandanReal
@DalandanReal 26 күн бұрын
So its still a biased pattern?
@violet_broregarde
@violet_broregarde 2 жыл бұрын
To fix your code, you need to store the results in a set, rather than a list. The contains() method of a set is way faster than that of a list. Your runtime is a parabola, you can get it down to a straight line. In other words, your code is O(N^2), but you can get it down to O(N).
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Interesting. I’ve never worried about Big O notation before because I’ve always been someone that has programmed for fun instead of work.
@ninjroidsolutions549
@ninjroidsolutions549 Жыл бұрын
@@BearTheCoder Great video! Just came to add to this comment. Big O improvements aside, a program of N print statements is still incredibly more expensive than N arithmetic/logic operations. Your program is as slow as it is largely because the CPU is constantly having to yield for I/O.
@BrystonB
@BrystonB 2 жыл бұрын
great vid
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thanks so much!
@Mr_shish_
@Mr_shish_ 2 жыл бұрын
Finally understood 👌🤞🤞
@profoundwill43
@profoundwill43 3 ай бұрын
Hey Beavis, what if every number was 69? Hehe yea, that'd be cool!
@innercircletradertevision
@innercircletradertevision 2 ай бұрын
😁😁😁
@Cutest1TheGame
@Cutest1TheGame 7 ай бұрын
I didn’t get the 🌈 flag joke, so I checked the KnowYourMeme database.
@imotvoksim
@imotvoksim 2 жыл бұрын
Came for the knowledge, stayed for the fun and aesthetics (and knowledge ofc)! Fun video, edits and the script! Keep going dude, your audience is niche but once the YT nerds find you, they will appreciate the effort (I hope). Fingers crossed!
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you! I’m enjoying making the videos as a journal I can look back on, so I don’t see myself stopping anytime soon! Though I have been really absorbed in a lot of other things the past few weeks so new videos are kinda stuck in the editing process… And I don’t think the topic is too niche, at least I don’t think. People like Michael Reeves and Code Bullet can garnish millions of views with every video, I just gotta get my videos up to their standards.
@armaanR
@armaanR Ай бұрын
amazing video man!
@raideno56
@raideno56 2 жыл бұрын
Nice ! you helped me thank you
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Glad I could help!
@iliasjabri1491
@iliasjabri1491 2 жыл бұрын
nice likes in this video
@abschmit
@abschmit Жыл бұрын
Noyce.
@Krazness
@Krazness Жыл бұрын
you smoked this video! Please keep creating content like this
@BearTheCoder
@BearTheCoder Жыл бұрын
Thank youi!
@ahmedhessain8765
@ahmedhessain8765 9 ай бұрын
This is just absolutely awesome!
The unexpected probability result confusing everyone
17:24
Stand-up Maths
Рет қаралды 637 М.
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 38 МЛН
Almost All Random Numbers Are Actually Fake
19:38
Thoughty2
Рет қаралды 512 М.
How To Predict Random Numbers Generated By A Computer
13:54
PwnFunction
Рет қаралды 548 М.
Why is this number everywhere?
23:51
Veritasium
Рет қаралды 8 МЛН
Random Number Generation (An Overview)
8:01
MacroPixel
Рет қаралды 4,1 М.
COS 302: Pseudo-Random Numbers
25:48
Intelligent Systems Lab
Рет қаралды 1,1 М.
Random Numbers - Numberphile
11:39
Numberphile
Рет қаралды 1,1 МЛН
[Explained] Perlin Noise and Unity
15:52
BearTheCoder
Рет қаралды 10 М.
Complex Numbers in Quantum Mechanics
19:57
Richard Behiel
Рет қаралды 167 М.
How to Generate Pseudorandom Numbers | Infinite Series
14:19
PBS Infinite Series
Рет қаралды 220 М.
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН