Randomness is calculated - Linear Congruential Generators Explained

Поделиться
HTML-код
  • Опубликовано: 16 июн 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...

Комментарии • 45

  • @benbalaj1732
    @benbalaj1732 Год назад +3

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

  • @arkadymarchenko1516
    @arkadymarchenko1516 4 месяца назад +3

    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  4 месяца назад +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.

  • @mhattaaldinor7548
    @mhattaaldinor7548 16 дней назад +1

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

  • @Sydney_Anuyah
    @Sydney_Anuyah Год назад +3

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

  • @vedanthkuchibhotla285
    @vedanthkuchibhotla285 2 года назад +1

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

  • @Cutest1TheGame
    @Cutest1TheGame 3 месяца назад

    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.

  • @Cutest1TheGame
    @Cutest1TheGame 3 месяца назад

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

  • @nekaamunoz
    @nekaamunoz 2 года назад +2

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

  • @lucaswoon6118
    @lucaswoon6118 Год назад +1

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

  • @ahmedhessain8765
    @ahmedhessain8765 5 месяцев назад

    This is just absolutely awesome!

  • @salah777
    @salah777 Год назад +2

    thanks for this great content I hope you get more subscribers

  • @violet_broregarde
    @violet_broregarde Год назад +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  Год назад +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 Год назад +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.

  • @estevaoyt
    @estevaoyt Год назад +1

    This is so goood! Thank you!

  • @imotvoksim
    @imotvoksim 2 года назад +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  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.

  • @Krazness
    @Krazness Год назад +1

    you smoked this video! Please keep creating content like this

  • @adibakkari7313
    @adibakkari7313 Год назад +1

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

  • @mithuncoorg65
    @mithuncoorg65 Год назад +1

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

  • @nkumarasena1409
    @nkumarasena1409 Год назад +1

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

  • @malvis8737
    @malvis8737 Год назад +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  Год назад +1

      en.m.wikipedia.org/wiki/List_of_random_number_generators

    • @BearTheCoder
      @BearTheCoder  Год назад +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 Год назад

      @@BearTheCoder thank you for your answer .

  • @jonasblom6177
    @jonasblom6177 2 года назад +1

    Great vid mate! Commenting for the youtube algorithm

    • @BearTheCoder
      @BearTheCoder  2 года назад

      Thank for that! Appreciate the love!

  • @JamesSarantidis
    @JamesSarantidis 5 месяцев назад

    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  5 месяцев назад +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 5 месяцев назад

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

  • @PvblivsAelivs
    @PvblivsAelivs 2 года назад +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.

  • @raideno56
    @raideno56 2 года назад +1

    Nice ! you helped me thank you

  • @Jozef13H99
    @Jozef13H99 2 года назад +1

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

  • @Mr_shish_
    @Mr_shish_ 2 года назад +1

    Finally understood 👌🤞🤞

  • @BrystonB
    @BrystonB 2 года назад +2

    great vid

  • @iliasjabri1491
    @iliasjabri1491 2 года назад +1

    nice likes in this video

  • @abschmit
    @abschmit 8 месяцев назад

    Noyce.

  • @Cutest1TheGame
    @Cutest1TheGame 3 месяца назад

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