Help with randomizing code.

Discussion in 'iPhone/iPad Programming' started by iAppleFan08, Feb 19, 2009.

  1. macrumors newbie

    Joined:
    Aug 26, 2008
    #1
    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. macrumors 65816

    Joined:
    Jun 29, 2007
    #2
    What do you mean, you just need random numbers?
     
  3. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #3
    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. macrumors regular

    xsmasher

    Joined:
    Jul 18, 2008
    #4
    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:

    http://www.eskimo.com/~scs/c-faq.com/lib/randrange.html

    use random() not rand() , though.
     

Share This Page