Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@irene theoretically an algorithm can be written to intentionally avoid that number, based on knowing how that PRNG works. But it would require intent and lots of work. But it could go on forever if they really wanted.
-
kleopi8706yanyone else who immediately has gauss distributions and expected values in his mind?
no?
okay... -
@Teknas untrue. The pigeonhole priciple does not state that every number will he hit. Only that at least one number will be hit at least twice. It's possible a number will never be hit.
-
Teknas22746y@deadPix3l assuming even distribution, the pigeonhole principal can be recursively applied to sub sections. Meaning every hole will eventually be hit.
-
@Teknas the pigeonhole hole priciple states that given n holes, you can prove that at least one hole will contain two pigeons given n+1 pigeons. They may all be shoved into one hole. There is no garentee that any hole will or will not contain a pidgeon.
Given a range of 0-n, one number WILL definitely be hit twice at n+1 iterations. But any given number is not garenteed to be hit at all. Also "normal distrobution" doesn't apply to PRNG. it may be true with the more popular ones, but it's not a requirement. -
Teknas22746y@deadPix3l agreed, but we have an infinite supply, so we will eventually hit.
Again, assuming even distribution. -
@Teknas roll a die. Then again. And again. Now explain to me, what properties of the universe require that it ever lands a six. Now take into account that microscopic changes in the die may force the weight toward another number, or the side opposite of 6 may be slightly rounded preventing it from ever stopping on that face. There are no guarantees
-
Teknas22746yIf you roll a die thrice,
You have a guarantee that it will land atleast twice before three or after three.
(1,2,3) or (4,5,6)
Now in subsequent rolls where the number is in the first set, apply the rule again.
With infinite tries, you will end up with each hole being chosen.
I guess we have to derive this as a proof or something in college. I don't remember the details. -
@Teknas yes. So given 9 holes and 10 pigeons, that garenteed that at least one hole contains 2+ pigeons. It does not guarantee that hole 2 contains any pigeons.
-
@irene I would argue that the following algorithm classifies as a PRNG:
Start with a seed value with n bits set.
Take the top 8 bits, convert to decimal.
Shift the seed by that amount, rolling bits over to the beginning. More mangling. But maintain that only n bits are set. Return and treat as new seed.
This is a terrible algorithm. But it is in fact an algorithm. And it's not really random. But it may appear random unless you spot the patern.. It's psuedo random.
This will never generate a number with x bits set, unless x==n -
@irene further mangling can be done. As long as the "n bits property" is maintained. Unless my math is wrong, a 64 bit int, with 6 bits set would be 64 choose 6 == 74974368 numbers.
-
@irene yes. And I quickly realized that mistake. And you are correct that it would only produce 64 distinct numbers. It was a bad implementation. But in later comments i specified that further mutations and shuffling would achieve my original intent.
But yeah. The first version is only 64 numbers. My bad. -
@irene it depends on what you consider valid. Although I believe we have reached an agreement. Linguistically, any algorithm that generates numbers via a psuedo random method is a PRNG. By valid I assume you mean "an algorithm that anyone would use or respect" then yes. Mine fails. But if you don't look under the hood, and don't modulus, and only look at the output numbers with the human eye in decimal (the bitwise patterns that make it bad will not be noticable in another base to most humans), you could naively believe it's decent when it isn't. Many people don't know which PRNG their language natively uses. So you could be using this terrible algorithm and not even know it. You probably aren't. The people who make those language decisions scrutinize PRNGs heavily.
But it's not infeasible that the PRNG youre using has some weird property that prevents certain numbers from being generated. -
@irene agreed. Modern PRNGs are really good. But I'm a pedantic asshole, and when you said "never" I couldn't resist a good internet argument of "well actually under these unreasonable and specific conditions, technically..."
But yeah. I wouldn't sweat it much. I couldn't even find an example of a bad rng. I had to make one myself, and got it wrong the first time :)
I wrote a little script that generates random numbers until it reaches 420, my luckiest go was 17. What was yours?
Script: https://sharecodesnippet.com/406
random
420
javascript