Randomness is calculated - Linear Congruential Generators Explained

Sdílet
Vložit
  • čas přidán 16. 06. 2021
  • 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/journals/mcom/199...
    Linear Congruential Generator Wiki:
    en.wikipedia.org/wiki/Linear_...
    "Random Number Generators" (Hull-Dobell Theorem) - by Hull, T.E. and A.R. Dobell:
    dspace.library.uvic.ca/bitstr...
    My Last Video on Perlin Noise:
    • [Explained] Perlin Noi...

Komentáře • 49

  • @benbalaj1732
    @benbalaj1732 Před rokem +5

    I wasnt expecting such a tastefully comedic and thorough explanation. I tip my hat you my good sir

  • @JZsBFF
    @JZsBFF Před měsícem +2

    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 Před 6 měsíci +4

    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  Před 6 měsíci +1

      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 Před 2 lety +3

    This is so awesome! I have never heard of LCGs until class today! And I got a far better understanding

  • @vedanthkuchibhotla285
    @vedanthkuchibhotla285 Před 2 lety +1

    By far the best video on LCG in YT. Top notch editing a bonus !

  • @mhattaaldinor7548
    @mhattaaldinor7548 Před 2 měsíci +1

    This is great and fun explanation of this algorithm, thanks a lot man

  • @tamenator
    @tamenator Před dnem

    Great explanation. Thanks for the links.

  • @ahmedhessain8765
    @ahmedhessain8765 Před 7 měsíci

    This is just absolutely awesome!

  • @nekaamunoz
    @nekaamunoz Před 2 lety +2

    Great video!! I love your editing. Keep it up! :)

  • @lucaswoon6118
    @lucaswoon6118 Před rokem +1

    This video was very nicely edit and informational :] thanks a lot

  • @Cutest1TheGame
    @Cutest1TheGame Před 5 měsíci

    @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.

  • @Krazness
    @Krazness Před rokem +1

    you smoked this video! Please keep creating content like this

  • @estevaoyt
    @estevaoyt Před rokem +1

    This is so goood! Thank you!

  • @imotvoksim
    @imotvoksim Před 2 lety +1

    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  Před 2 lety

      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.

  • @salah777
    @salah777 Před rokem +2

    thanks for this great content I hope you get more subscribers

  • @violet_broregarde
    @violet_broregarde Před rokem +3

    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  Před rokem +1

      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 Před rokem +1

      @@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.

  • @adssib04
    @adssib04 Před rokem +1

    Goodddam it ur awesome bro , keep it up
    ur videos are soo good GL

  • @Cutest1TheGame
    @Cutest1TheGame Před 5 měsíci

    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.

  • @nkumarasena1409
    @nkumarasena1409 Před rokem +1

    woah tommorow is my crypto exam and this helps me lot mate thankz:D

  • @jonasblom6177
    @jonasblom6177 Před 2 lety +1

    Great vid mate! Commenting for the youtube algorithm

  • @mithuncoorg65
    @mithuncoorg65 Před rokem +1

    How does number 8 comes after 5,7,7 in linear method please explain.

  • @malvis8737
    @malvis8737 Před rokem +2

    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  Před rokem +1

      en.m.wikipedia.org/wiki/List_of_random_number_generators

    • @BearTheCoder
      @BearTheCoder  Před rokem +2

      “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 Před rokem

      @@BearTheCoder thank you for your answer .

  • @raideno56
    @raideno56 Před 2 lety +1

    Nice ! you helped me thank you

  • @Mr_shish_
    @Mr_shish_ Před 2 lety +1

    Finally understood 👌🤞🤞

  • @PvblivsAelivs
    @PvblivsAelivs Před 2 lety +1

    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.

  • @Jozef13H99
    @Jozef13H99 Před 2 lety +1

    Also commenting for the algorithm. This was a fun watch ^_^

  • @BrystonB
    @BrystonB Před 2 lety +2

    great vid

  • @JamesSarantidis
    @JamesSarantidis Před 7 měsíci

    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  Před 7 měsíci +1

      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 Před 7 měsíci

      @@BearTheCoder Ah, I see. Thank you both for the explanation and the video :)

  • @profoundwill43
    @profoundwill43 Před měsícem

    Hey Beavis, what if every number was 69?
    Hehe yea, that'd be cool!

  • @iliasjabri1491
    @iliasjabri1491 Před 2 lety +1

    nice likes in this video

  • @innercircletradertevision

    😁😁😁

  • @abschmit
    @abschmit Před 10 měsíci

    Noyce.

  • @Cutest1TheGame
    @Cutest1TheGame Před 5 měsíci

    I didn’t get the 🌈 flag joke, so I checked the KnowYourMeme database.