My recomended sites

Here is a short list of sites that I check on a daily basis. This is where I get my news and information about all that is going on in the interwebs.

Digg is a place for people to discover and share content from anywhere on the web.

DZone is a free link-sharing community for developers, anyone can submit new links to the incoming queue, members vote on upcoming links to determine what gets promoted.

Blog focusing on AJAX technologies and trends.



Lastest blog posts

Objective - C and Random »February 25, 2009 1:13:52 PM

comments ()

So I am working on an app, like always, and it needed to generate a random number from 0-3 no problem I thought and just typed in random() % 3; thinking that would be fine. Well it kept returning the same exact sequence!!! So how is that at all random? After about a half of an hour I found arc4random(), switched it our for random and it works like a charm :)

This is one of those huge gotcha's for me, I assumed that random() would generate a random number but its pseudo random. The arc4random() uses a superior algorithm to rand. You don't even need to set a seed. So just a small note to anyone else so that they don't get tripped on why random() is generating the same number. Sure you could have approached this other ways like set a SEED but this seems to be the simplest approach.



del.icio.us Reddit TwitThis Facebook StumbleUpon Mixx Technorati Google

Comments:

  • Name:
  • Comment:
  • CAPTCHA Image
  • CAPTCHA: