It is not suggested to use an rng with a known statistical bias, when a random number is required.
It is not suggested to use an rng with a known statistical bias, when a random number is required.
Like, all LFSRs are RNGs with distinct statistical biases.
You wouldn't want to use an rng with a bias in picking cards for a game of poker. Using an LFSR is also a solved probem. You could transform an LFSR using a markov chain to remove some of the properties inherent in the LFSR. All that takes is some table lookups.
Naively, I'd assume that if you give me a biased RNG with a known distribution, I'd think I could just unroll the distribution back to something uniform.
This needn't even involve division per se. A simple lookup table should suffice.
def uneven_random():
# return 0 with 2/7 probability, 1 with 2/7 probability, and 2 with 3/7 probability
n = random.random()
if n < 2.0/7: return 0
if n < 4.0/7: return 1
return 2
def transformed_random():
# return 0 or 1 with 50% probability
N = uneven_random()
while N == 2 : N = uneven_random()
return NOf course, the meeaning isn't that people aren't to work on crypto but that people shouldn't create RNGs like this thinking they are better than the prior-art, when they actually regress with already solved probems.
This is the exact different between arc4random() and arc4random_uniform().
arc4random_uniform() is recommended over constructions like
arc4random() % upper_bound as it avoids "modulo bias" when
the upper bound is not a power of two.
Unfortunately when I google for ios random number The very first return says We can use the C function rand() for this:
int i = rand()%10+1;