Random Numbers (How Software Works)
HTML-код
- Опубликовано: 6 сен 2024
- How Software Works is a book and video series explaining the magic behind software encryption, CGI, video game graphics, and a lot more. The book uses plain language and lots of diagrams, so no technical or programming background is required. Come discover what's really happening inside your computer!
This episode is about random numbers--why software needs them, why they can't really make them, and why that's okay.
Learn more about the book...
- At the Amazon page (amzn.to/1mZ276M).
- At my publisher (www.nostarch.co...)
- At my site (www.vantonsprau....
If you'd like to contact me visit my site (vantonspraul.com), or just leave a comment below. Suggestions for future topics are welcome!
I knew it would be impossible just by the very nature of computers, so I always wondered how it works... Thanks for explaining it...
on regular computer's it would be impossible. But for a quantum computer, it would be a piece of cake
@@jeremiahnoar7504 Also possible on a regular Computer, if you plug in a Hardware-RNG or use a CPU with an on-board hardware random number generator.
Hey its random to see u here lol. I'm Jacob, one of Dylans friends
@@jacobstewart6014 Nice
@@Manic97LP never truly random
Pretty interesting. Good animations!
Random function in programing languages was always something
that intrigued me
Thank you! I never put much thought into randomness in software until I started programming, and you gave me exactly the answer that I was looking for. You got yourself a like & a new subscriber.
me too what language do u code?
I code C# and C++ and Python
LOL
BYE
!!!!
6:07 Universe.exe has stopped working.
Excellent video; answers well a question I've had floating in my mind for years!
thank you for making this video i've been looking for an answer for quite a longtime now but everywhere i looked there was only sowtware tutorials.
as i thought computers can only emulate random.
Viewed 3 videos on RNG.
This is the ONLY one that was worth the watch.
Great explanation. At first sight, i thought computer needs a starting reference to generate some random number, so they must used something like, declaring a variable and accessing its random, which is supposed to be random and then taking the last digit as the random reference. Seems like the seed thing is kind of similar.
I'd check out your book sure
4:36 straight answer. you're welcome
Is it always multiplied by 8 and divided by 11? Or does that change?
Such a neat video ! Answered the exact question I had in my mind!
Damn, 4 years ago and still relevant. By far the best explanation I've seen. Thanks!
Python 3.6 released the "secrets" module. It's a secure non-deterministic RNG that is real easy to use. It's just a easy as the "random" module.
AFAIK, the secrets module repackages calls to something like os.urandom, which itself is a repackaged call to the underlying operating system to get the random number. So if the OS and hardware supports non-deterministic random numbers, that's what you will get, and if not, you will get a (hopefully well-implemented) software-regenerated pseudorandom number. Point is, the secrets module is not producing the random number itself, and it didn't any new functionality, it just made the ability to call the OS for random numbers more visible, to get programmers to use that feature when strong RNG was needed. You probably already know all this, and I am probably going on too long, I just didn't want someone to read your comment and think that Python had created a non-deterministic RNG in software.
1:53
Men you are a genius! Such a great video. Perfectly explained so that everyone can understand it
Very well explained! I hope I can apply some of that knowledge in my future projects!
This helps a tonne thankyou V. Anton
This question was asked to me in an interview.
Generate Random number without using random module in Python?
Now I know the answer.
Really well explained, thank you!
I was curious about the real random numbers, simple way to explain and understand the concept. Good teaching skills.
Thanks! Glad you liked it.
Company: "Play our new exciting adventure where you can control a party of 6 characters across dungeons, mountains, kill dragons and marry the hot lady in the end"
Me playing it: "My entire party is missing attacks on this Rat"
You saved my simulation class, you rock!
Just a random (🤣) thought, which method does Excel’s Rand() function use?
Very good explanation, I enjoyed it a lot too.
That’s a good easy to understand explanation, thanks
ok
So how do the numbers 8 and 11 change if your have a different rang of numbers? How do you know which two numbers to use?
Good explained! Thank you.
5 x 8 = 40.
40 divided by 11 = 3.6363636
So where did the 7 come from?
It's not the quotient, it's the modulo -- the remainder. 11 goes into 40 3 times, with a remainder of 7.
@@vantonspraul oh. Thank you. Now I understand.
Mathematical explanation plz...how 5×8 ÷11 =7?????
What i do for 0 to 9 random number
@@maheshkshirsagar8432 It's not division, it's the remainder of division. So not 40 divided by 11, but the remainder. So 40 divided by 11 is 3. But 3 times 11 is 33, so the remainder is 40 - 33, or 7.
This was really well explained thanks!
I still have questions about which processors have the lamp example and how to generate some random numbers that way
It's an analogy to circuitry inside Intel processors since Ivy Bridge, accessed via a new RdRand instruction (en.wikipedia.org/wiki/RdRand).
Im not even an programmer or engineer and that made sense to me. Strong explanation
(edi) or I hope I understood...
Glad you liked it! It was meant to be understandable to non-programmers, so I'm glad to hear I got that right.
That was SO well explained! thank you so much and keep it up
Excellent explanation!
Im a jurassic park fan, and i did not expect that reference, well done you surprised me!
4:44
the wither is easier to kill at 5:23 PM than any other time
jk
but there probable exists some time frame where you could predict the wither's movements
Yeah but probably you'd have to know the time in ms, and since there's always some sort of delay (slowness of the computer) which is influenced by for example temperature--> influenced by atoms and energy etc and because of the Heisenberg principle it is random
@@laurenzv5682
true, very true.
and you would need to know the state of the variables first, which would involve seeing the code
I can actually say that this is not true (at least in java edition, I don’t know much about C++), or at least a little more complicated than the time you spawn it. Java has a class called Random which can give you random numbers. To create a random, you can input a seed, or leave it empty and it will create a random seed probably using something like system time. In Minecraft, most randoms use the same seed, which is the seed of the world. This is why every world with the same seed randomly generates the same way.
I haven’t looked much into Minecraft’s code or MCP, but I will say that it’s probably about when you make the world, not when you spawn the wither.
Riemann hypothesis.
Just search it. If you solve you can predict next otp.
Amazing video! I always wondered how does the random function of a calculator works
nice video thanks
one of the unique videos i have seen about computation theories and how things work... thanks for that knowledge..... keep it up :)
i don't dig the lamp scenario
so, you turn the right lamp on, it tells the left lamp to turn off, which it does. then what? there'd be no point in the left radio sending another signal to the right lamps to say "i'm off, so you need to switch on", then the right radio saying "i am on, so you need to switch off" and so on, so they would probably just leave it there
so if the lamps were in a normal position, left light on right lamp of and you pulled both chords at once, then what would surely happen is that the left lamp would switch off and the right would switch on, for about a second before returning to their original state, and that would be that
and if the lamps were both somehow off, then the same thing would happen, the lights would come on, both send a signal and turn each other back off, then as far as the radios are concerned their jobs done so the lamps would remain off
the analogy to game play was very helpful
Wow! really great lesson. Eagerly waiting for your book to come out.
***** Thanks! I should have a couple more videos up by the time is book is out.
Thanks. Now I understood how random numbers generates.
The lamp example had me thinking about the racing condition in the J-K flip flop.
That's spot on. The real-world device that example is based up is basically two flip-flops in a cycle.
4:02 About the couple of problems: One of them is, that this line is going to repeat itself as soon as one of the numbers appears as seed a second time. Or did I get it wrong?
Fascinating!! :D
great to know that there is no little gnome throw the dice in my pc btw what is the game name at 1:14
That is The Secret World, a horror MMO that I was really into at the time. It has since been reborn as the free-to-play Secret World Legends. I don't like the progression system in the new version as much, but honestly the storytelling is the reason to play it anyway.
@@vantonspraul haiya thanks for answer
3:15 how they produce no. 7 ?
5*8÷11 = 3.63 ?
yes yes yes here I have got the answer of my question. I want to make a software to get the predicted number by using previous draw result. please if you have more videos for predictable number generating software or any other tools to get help then please repply. thank you again
How to workimg random number in lottery
thanks
Thanks for the video... always wondered about this....
your maths degreee and knowledge is fine and all that, but how does it stop souble skulls in a reroll?
I might get called stupid for this but i really struggle to see how anything could ever be random? A coin flip’s outcome is determined by the force applied, the movements of the atmosphere around the coin, the distance and surface of the plain its falling to so the outcome can be determined with enough information. I feel this applies for absolutely everything. With enough information of the trillions of factors involved you can predict almost any outcome. This means that everything in the universe is predetermined but seems random just because of the amount of complexity and the variarity and number of factors involved. Can someone see problems in this theory because ive been struggling to prove my self either wrong or right for a while now
You are getting into some high-order philosophical questions with this. Indeed, some people don't believe in human free will because of this argument (although, if you are convinced to have an opinion by an argument, that would imply you have free will to choose or reject it).
In any case, you could be right that even truly random numbers are not random if we mean happening by chance. But if we mean unpredictable, then yes, some numbers are truly random, because there seems to be no way to predict them the way we can with pseudorandom numbers. It might look like there's at least a theoretical way to determine the states of all the variables, but there probably is not, because of the uncertainty principle.
@@vantonspraul but are my thoughts not predetermined by a multitude of factors? Like the sum of my life experiences and so on? It seems to me that each of my decisions in life could have been predetermined? (only theoretically because no man could have the amount of information required) it seems to me that a hypothetical super computer that knows absolutely everything and can calculate that incoming information could also determine everything that is to happen. The way you mentioned in the video to make true random numbers still seems only pseudorandom to be because the speed of those radio waves would be determined by the atmosphere and other outside factors and if you could know all of their effects you could predetermine the supposedly random number that is to be generated. At least this is what seems to make the most sense to me but i seek a higher understanding that is why i made the comment, to see other peoples opinions and hopefully have a discussion
@@user-iy6oe9kp4f You'd enjoy watching Veritasium's video "What is not random?", and Vsauce's video "What is random?"
@ that is a very good recommendation, i have watched both before coming up with my question but none the less both videos are extremely informative and entertaining
So you use lamps to create random numbers?
So, the lamp turning on and off will eventually stabilize and stop being random, right? So, to capture the truly random part we just take the input from the initial "frantic" behaviour of the lamps?
Maybe an API that queries a Lava Lamp Farm would make it more random.
😂
This is a great video, however the issue I'm having with the lamp analogy is that you mention the lamps are initially turned on at *exactly* the same time, but the signals would arrive to each other at only *nearly* the same time. What is happening in a circuit that they don't arrive at *exactly* the same time and how does that change with each trial? What are the random variances, i.e. "chaos theory?"
The Heisenberg principle
What Is the name of the random generator circuit you talk about at the end?
If we can prove that true random numbers are deterministic and are bound by a physical law we can predict the outcome. Which would proves that we have no free will
Just started doing unity and I though it would be impossible without random.range or something similar.
Success in your new publication.
Gabriel R. here!
***** Thanks, Gabriel! Hope you are doing well.
Can you make another going into full detail the part about how a computer itself makes a truly random number?
Does it use a literal light source with sensors or is it just 2 signals repeating till one maintains?
I remember using winamp around 2000 the random play option always played the same songs like forever. If I had a playlist of 100 songs, it was only playing about 20 of them, I hated that and thought it can not be random, but I could not know why.
Did anyone experienced this thing?
EXACTLY... most media players I used had that problem, surprisingly... in the case of Winamp at least I could set keyboard hotkeys like Ctrl+Alt+R to toggle Shuffle On and Off, so if I toggled it off, skipped a track, and turned it back on, the Random Number queue would reset for a while
Winamp best player, still using it in Windows 10
🙏🙏
Very well explained, thanks.
exactly what i was looking for !
Glad to hear it!
Very good and Informative ! Is Noise another way to generate the seed for Pseudorandom ? or Is noise used only for True Random generator ? Hope you can help with this
Thank you :)
Nice Video!
I really wish to know how a random number comes twice or thrice in a role
So helpful.... Thanks!
You're welcome! Glad you liked it.
Really helpful.
does a modulo of 11 is always used?
Can rng be controlled by developers?
yes, they can reprogram rng or change it somehow so rng works in same but different way
I was watching this at 7:33 PM when i was at 4:43. Am i in a Matrix? what a coincidence
what about pokersites, they also use random cards(numbers), is there any explaination?
That's a great question. I don't know about poker sites specifically, but I do know that electronic casino gaming machines, such as slot machines and video poker, have to deal with random number generation. Also, the mechanical shufflers that casinos use employ random numbers--instead of just haphazardly mixing cards, the way a human shuffler would, shuffling machines effectively assign a random number to each card position in the deck then sort the cards based on those numbers. I understand that early shufflers and some early electronic casino games used the kind of algorithm I show here for random numbers, and were therefore potentially vulnerable to prediction (although I don't know if this was even profitably exploited). Now I expect they use hardware-generated random numbers but I don't know for sure.
'How random random numbers actually are.'
'Well that part is little complicated. '
Awesome Lessson!! Kindly make a video on "Design Patterns for a layman".
rohit rawat Thanks for the suggestion. That's a "Think Like a Programmer" topic...design patterns are covered some in the TLAP book, but let me see if I can develop a good video on what you're suggesting, an intro to the concept.
Great video, thank you
thank youu
This is plain wrong. Software can produce nondeterministic random numbers when the instruction set of the computer has nondeterministic instructions. Every current X86 CPU includes two nondeterministic instructions - RdRand and RdSeed. Software is just an assemblage of CPU instruction and if some the the instructions are nondeterministic then so can the software be nondeterministic.
What exactly is "plain wrong"? I don't mean to be snarky, but: did you watch the entire video before posting this comment? Starting around 5:20 I talk about how some processors have instructions to produce truly random numbers for use by software; this was still a fairly new feature at the time when I made the video.
@@vantonspraul I mean it is plain wrong to say software cannot be nondeterministic. Obviously it can be if the underlying instructions include nondeterminstic instructions. Your explanations of the relationship between deterministic software and hardware that grants it access to nondeterministic data is correct, but the characterization of software being always deterministic is not right.
Is it possible to generate a seed from a series of random numbers,like in the lotteries
I am also looking for it, if u know please let me know
No starch books are the best
very well explained. Subbed!
Thanks!
Thanks! That actually make sense.
@2:22 I knew it
Actually there is no such thing as true random. Thanks for the video! Very cool
What if the numbers are not 1 through 10, but 1 through 15?
now the only question i have is, where does minecraft get its seed from
Amazing!
2:52, uh, in the range from 1-10, uh, modulo result can output 0. So its actually 0-10.
No, as shown, the sequence produces only numbers in the range 0-10. Of course, if 8 times the seed (previous number in sequence) ever produced a multiple of 11, then modulo 11 would result in a 0. But we choose a multiplier and initial seed to avoid that, because if we ever get a 0 in the sequence, we'll just keep generating 0s thereafter.
V. Anton Spraul oh, oops. Should’ve double check that. Sorry.
i was sitting in class one day thinking how in the world does a computer generate a random number, there's no way that's possible
How we stabilish a range with pseudorandom?
the modulo
What if I need a random number from the range of 1 to 7? How many trials do I need to make them equally likely?
I’m watching this because I have shitty RNG
Jelwi HAF he’s making a joke about video games
Why was that sofa there
Now I have anxiety about the number I generate.
i can not understand your lamp example
learn about the chaos theory
simple:
if one lamp is turned on, the other is off
if you click both buttons from both lamps at the same time, it is random which one gets turned on and which one gets turnes off
I guess for the true random one, it will eventually become transistors
Am i a nerd if i tought about how a pc could generate something random and then google it? 😂
What game is that at 1:12?
World of Tanks
Now I can beat electronic keno