Thoughts from the Furry Tail Apps gang We create apps for iOS and Mac.

23Nov/100

Improving the randomness of dice

We’ve gotten some feedback on Backgammon Board HD, that the dice aren’t experienced to be random enough. So we’ve looked into it and will try another technique for generating the dice values.

Previously, we’ve been using the arc4random() method to generate dice values, for example:

int dieValue = arc4random() % 6 

I stumbled upon a blog post from another game developer, where they’d compared three various methods for randomizing values. Inspired by their result, we’ve decided to implement another approach instead:

UInt32 randomResult = 0;
int result = SecRandomCopyBytes(kSecRandomDefault, sizeof(int), (uint8_t*)&randomResult);
if (result != 0) {
randomResult = arc4random();
}


return randomResult % 6;

We’ll be testing this and hopefully shipping it soon with the next version (1.1) of Backgammon Board HD.

A big thank you to Nathaniel Kelso for the feedback. Nathaniel will be gifted a free Backgammon Board HD for his contribution!

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.