How to get high-quality random numbers on iPhone or iPad?

I know that arc4random () is considered one of the best randomness options. But still, he tends to give obvious duplicates and repetitions several times.

I was thinking about using accelerometers to add some real randomness to the arc4random output. Before I spend several weeks developing a better solution: what other solutions are available?

+3
source share
5 answers

In response to your real question, if you want something better than arc4random (), check out

mersenne twister

which in certain ways is "better." Hope this helps!


, , , , !

"

" , " "" - .

+4

. " " ; arc4random /dev/urandom, .

+6

( arc4random ), , , . , .

- , , .

+5

"-" ... arc4random(), . , .

:

if (!self.dictionaryValues) {
[self loadList];

} else {

NSMutableDictionary *unusedValueList = [[NSMutableDictionary alloc] initWithDictionary:self.dictionaryValues];

int random = arc4random()%[self.dictionaryValues count]; // note, crashes on nil;
int i=0;
for (NSString *key in self.dictionaryValues) {
        i++;
        if (i == random) {
            NSLog(@"MATCH! on key=%@", key);
            [unusedValueList removeObjectForKey:key];
        }
}
self.dictionaryValues = nil;
self.dictionaryValues = unusedValueList;

}

, !

+2

Source: https://habr.com/ru/post/1790189/


All Articles