General > General Technical Chat
Odds seem too high when guessing random zeroes and ones
SiliconWizard:
As I mentioned, PRNGs are not trivial things.
Even if your base PRNG is decent, once you multiply/divide its output by a given ratio to change the scale of the output, you're going to screw up the characteristics of the PRNG more or less drastically depending on the PRNG and the scaling ratio. If the scaling ratio is very small, like in this case (we can assume that the base PRNG has a native 32-bit width), scaling it down to [0, 1] will probably make the characteristics of the ouput pretty ugly on a short term. Sure it's more or less going to be 50% on average for a very long sequence, but it's very likely to have relatively 'long' same-bit patterns on short term.
I would highly suggest rolling your own 1-bit PRNG for this. Additionally, it's a fun exercise.
RoGeorge:
I always thought modulo division is the proper way to bound the randomness of a big number to a given range.
Are you saying that if we divide a big pseudo-random number by n, the remainder is no longer a pseudo-random [0..n)? I don't understand, why/how the randomness would be lost?
Psi:
In many cases where you need randomness for visual stuff, you're better to have a block of memory/eeprom where you hard code a chunk of random data. Then you can step through the data by 1, then by 2, then by 3 etc.. to create a much larger block of random data. You can pre-filter the data to ensure there's no long blocks of the same numbers, which can happen in true random data but may be undesirable in some applications.
You can even use a psudo random number generator to index your block of custom random data etc..
Karel:
--- Quote from: RoGeorge on April 01, 2023, 08:32:58 am ---I always thought modulo division is the proper way to bound the randomness of a big number to a given range.
Are you saying that if we divide a big pseudo-random number by n, the remainder is no longer a pseudo-random [0..n)? I don't understand, why/how the randomness would be lost?
--- End quote ---
I would like to know that as well. Any experts here willing to comment on that?
alm:
--- Quote from: SiliconWizard on March 31, 2023, 09:15:47 pm ---Even if your base PRNG is decent, once you multiply/divide its output by a given ratio to change the scale of the output, you're going to screw up the characteristics of the PRNG more or less drastically depending on the PRNG and the scaling ratio. If the scaling ratio is very small, like in this case (we can assume that the base PRNG has a native 32-bit width), scaling it down to [0, 1] will probably make the characteristics of the ouput pretty ugly on a short term. Sure it's more or less going to be 50% on average for a very long sequence, but it's very likely to have relatively 'long' same-bit patterns on short term.
--- End quote ---
I'd be curious to see a reference about this. As far as I know a PRNG just generates a number of bits of randomness, and has no knowledge about what these bits mean. Obviously you might lose resolution if you multiply / divide an integer by a large number (like shift right 16 bits), but that is nothing specific to PRNGs.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version