Help with randomizing code.

Discussion in 'iOS Programming' started by iAppleFan08, Feb 19, 2009.

  1. iAppleFan08 macrumors newbie

    Aug 26, 2008
    I'm trying to create an app that includes a lot of randomizing. Unfortunatly, the only access I have to a sample code that deal with randomizing is in this one example where when I try to take the randomizing part out of it and put it in my own code, it doesn't want to work. I've changed it, morphed it, combined it, and nothing happens. Can someone please help me. I need just the randomizing code itself (not mixed in with a whole other code as well...).
  2. detz macrumors 65816

    Jun 29, 2007
    What do you mean, you just need random numbers?
  3. eddietr macrumors 6502a

    Oct 29, 2006
    There are quite a few people on the board willing to help. Just post the code you are working on and tell us what you expect it to do. And also what it is actually doing. And if you're getting errors on compilation or when running it, make sure you copy/paste the exact error.

    If you do that, I'm sure someone will help.
  4. xsmasher macrumors regular


    Jul 18, 2008
    The simplest way to get a random number between 0 and 10 is

    int myNum = random() % (10 + 1);

    It's really a C question, not an iPhone question. If you need something more complex, read this:

    use random() not rand() , though.

Share This Page