Random Numbers?

Discussion in 'iOS Programming' started by lynkynpark86, Jan 27, 2011.

  1. macrumors 6502

    I am making an iPhone app to randomly pick a 6-digit ticket number from about 500 numbers. The app will be run in the simulator. It is for a technology-related contest, and the fact that I am using an iPhone app is entirely for show. I wanted to use an NSArray, but I think loading the data from a file will be much easier than that, since the tickets are going to be scanned, so I will already have all the numbers in a .txt file. How can I load 500 numbers from a txt file, with each of the 500 numbers on a line, totaling 500 lines? Is there some way to do something like:
    NSArray *tickets = [NSArray arrayWithObjects:[pathToResource:"tickets" of type:"txt"]];
    If that worked, it would be perfect
  2. macrumors 6502

    Oct 5, 2008
    La la land
    You can't just do that. Google around. You basically have to do this in a kind of three steps:

    1. Locate the file, get the path
    2. Load the file
    3. Convert them to NSArray.

    BTW out of curiosity how did you format the file? Just numbers separated by line breaks? If it was more structured like XML or something like that it might be easier. Maybe.

Share This Page