How can you generate Multiple random numbers from 1 to 49?

I am very new at programming with the iPhone SDK and I need some help with a project I am working on. What I want to do is set up a window with 6 labels and 1 button. When the user clicks the button, the program will populate 6 randomized numbers each ranging from 1 to 49, and then place each of 6 numbers in a label. But each time the program ends and starts again the numbers cannot be the same, and also when the user clicks the button, no label can have the same number twice, so for example. If label 1 had the number 10, the other 5 labels cannot have that number until the button is clicked again. I know how to set up the interface, I just need the code. I would so greatly appreciate someone's help in this matter. I have been trying to do this for days and I cannot figure it out. Possibly someone who knows tons about Objective C programming can help me!
Thank-you so very much!!

I see that you're writing a lottery number generator. Perhaps the easiest way to do it is to emulate a real lottery: fill an array (NSMutableArray, probably) with the numbers between 1 and 49, pick one at random, remove that number from the array, and repeat. (You can think of the numbers as being the balls and the array as being the machine that pops them out.)
One simple way to get the random indices needed is to extract six random bytes from Randomization Services using SecRandomCopyBytes, then loop over them, using the modulo operator (%) to select an index within the size of the array.
And no, I'm not going to write your code for you. If I was going to do that, I could package and sell the app myself.

Similar Messages

  • How do you generate multiple random numbers between 1 and 49

    I am new at mac programming and I want to make an iPhone app with the free SDK. What I would like to try is a random number generator. I imagine it as when the user clicks a button 6 random numbers from 1 to 49 would appear in a label or another control. If someone could please give me the code that would place these randomized numbers in a label I would greatly appreciate it. I know how to link all the controls together, I just need the code. Thank-you to anyone that can help!

    semi-sudo code goes here
    --prepare and array which will have number from 0 to 49
    --loop thru the array like this
    int i=0
    for (i; i<=49; i++) {
    int a=arc4random() % 49] ;
    int b=arc4random() % 49];
    --here exchange the objects so that they are shuffled
    [myArray exchangeObjectAtIndex:a withObjectAtIndex:b];

  • How can you generate a random number?

    Say I have a timer, and I need it to choose a random number between 100 and 1000. How would I do that?
         timer.delay(***RANDOM***);Thanks!

    I have this, and it's working for me:
    int j = rand.nextInt(500);
    But I actually want it to generate a random number between 100 and 500, not 0 and 500. How could I do this?
    ~Dac

  • How can I generate multiple unique random numbers?

    Hello,
    I am trying to generate multiple random numbers between a given set of numbers (1-52) and not have the same number generated twice within that set. I can compare the last and next numbers with the compare function but how would I go about comparing all of the generated numbers without using a huge list of shift registers...
    Any help/ideas are welcome and appreciated.
    Jason
    Solved!
    Go to Solution.

    Here is an implementation of Jason's solution.
    steve
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.
    Attachments:
    random.vi ‏10 KB

  • How can you pull in pdf's from iBooks and bring them into the Box app?

    How can you pull in pdf's from iBooks and bring them into the Box app?

    That sounds great, but I'm lost.
    I followed these steps:
    1) Open your PDF (in Adobe Acrobat Pro)
    2) Chose print
    The print/printer options pop-up will show.
    3) In the printer section, do not use your normal printer, a printer named Adobe PDF should be an option. Chose it.
    4) Under the "Page handling" section, change the Page Scaling drop-down menu to "Multiple pages per sheet".
    It works fine, but it looses all of the font information and the search no longer works. How can you do it and save the font info, so the search tool continues to operate.
    Am I missing anything?

  • How can I remove multiple duplicate photos from Photoshop Elements 6 catalogue?

    How can I remove multiple duplicate photos from Elements 6 catalogue?

    Newer versions have similarity recognition software but in PSE6 you have to do it manually.

  • TS3899 How can i delete multiple e-mails from my iphone 4S. There are indicated more than 1500 e., but when i open the file there is indicated: no e-mail.

    How can i delete multiple e.mails from my iPhone 4 S. ? It shows the presence of more than 1500 e-mails. But when I try to open the account it shows that there a no e-mails. So i cannot delete them.

    I would disconnect the email on your phone...
    And reconnect again and if it still does that go on an actual computer, log on and delete the mails with ease...
    Hope this helps..it may just need to be refreshed...

  • How can I add multiple email addresses  from spreadsheet into email?

    how can I add multiple email addresses  from spreadsheet into email?

    I have tried that, but the system reads the emails as one long email and I can't find any way of separating them - it ignores spaces, colons and I have also tried putting them through a word doc... still does not work. It works perfectly easily on a PC system!! ( I have just moved to a mac!)
    any ideas would be good
    thanks

  • HT3702 How can you remove a credit card from your account?

    How can you remove a credit card from itunes account?

    See if this support document answers your question. Why can’t I select None when I edit my Apple ID payment information? - Apple Support

  • How can you delete a Pages document from your Ipad but keep it on your MAC?

    How can you delete a Pages document from your Ipad but keep it on your MAC?

    You will need to keep them in folder on your hard drive somewhere other than in iTunes or they will be deleted from iTunes if you delete them from the device. I have a folder on my Mac called iPad Pages Documents - very original don't you think!
    Here is the support article that explains it all.
    http://support.apple.com/kb/HT4094

  • How can I Generate two different reports from single execution of Test cases in NI teststand

    Hi,
    My requirement is to generate two different reports from NI teststand. One for the Logging of error descriptions and the other report is by default generated by the Teststand. How can i generate a txt file that contains error descriptions other than that mentioned in the default report?
    Solved!
    Go to Solution.

    Do you need to do that just for these two sequences but not for other sequences? I don't see a problem to use SequenceFilePostStepRuntimeError. Create this callback in both sequence files and configure them to log into the same file. SequenceFilePostStepRuntimeError callback is called after each step of the sequence file if it has runtime error. You can access the calling step error information via RunState.Caller.Step.Result.Error property. Take a look to attached example.
    The "other way" is useful if you need to log errors not for every step of the sequence file, but for some of them. This is more complex, because you need to create a custom step types for these steps. For the custom step you can create substeps (post-step in your case) which will be executed every time after step of this type executed. Then, this is you job to determine if error happened in the step, acces to step's error information is via Step.Result.Error property. 
    Also, be aware that step's post-expression is not executed in case of error in the step.
    Sergey Kolbunov
    CLA, CTD
    Attachments:
    SequenceFilePostStepRuntimeError_Demo.seq ‏7 KB

  • How can you combine multiple PDF pages into one searchable PDF page?

    I have scanned multiple business cards and now have a PDF  file with over 500 pages (or cards). I would like to be able and create a  page with 8 cards to a page and is still searchable for text. Right now, the text is searchable. Basically have 63 pages and not 500.
    Example:
    If I wanted to find Joe Smith's card, I could search for  "Joe Smith" and it would search all of the text and bring me to the  page(s). Right now, it will bring me to that page. Is there a way to create  a page where I can have multiple cards and the text is still searchable?
    I tried to create a page in Photoshop, made 8 different layers with 8  different cards, but when saved, not only was the file way too large, but no text, or font, was detected  and there was nothing to  search for.
    Is there an option to create a page in Acrobat Professional and put 8 cards to a page?
    I have InDesign, Illustrator, Photoshop and Acrobat Professional Pro.
    Thanks,
    mr19th

    That sounds great, but I'm lost.
    I followed these steps:
    1) Open your PDF (in Adobe Acrobat Pro)
    2) Chose print
    The print/printer options pop-up will show.
    3) In the printer section, do not use your normal printer, a printer named Adobe PDF should be an option. Chose it.
    4) Under the "Page handling" section, change the Page Scaling drop-down menu to "Multiple pages per sheet".
    It works fine, but it looses all of the font information and the search no longer works. How can you do it and save the font info, so the search tool continues to operate.
    Am I missing anything?

  • How can you upload photos to FaceBook from iPhoto without using the sync where is deleted in iPhoto it will be deleted in FaceBook

    How can you upload photos from iPhoto to FaceBook without having the sync where if you delete from iPhoto you delete

    I think you have to have the files on your HD. So either put them in iPhoto or copy them to a folder in Finder, and from there you can upload to Facebook.

  • Generate multiple random numbers?

    Hi,
    I'm trying to generate random numbers using Math.random()* n;
    but I want the random numbers to reset to something different after
    a particular event is called. Instead, I've noticed the numbers
    either buzz away randomly in every frame (when placed inside
    onEnterFrame), or it picks random numbers once, and then uses those
    same values over and over (when placed outside the onEnterFrame).
    How do i get actionscript to generate new random numbers
    after each myMC.onPress = function(), or alternatively, after a
    score changes (like some kind of watch feature?)

    ok, i've got a half working version;
    function ranbot(x) {
    return Math.ceil(Math.random()* x) + "/" +
    Math.ceil(Math.random()* x);
    trace(ranbot(60));
    but is it possible to set up the function so the numerator is
    equal to or less than the denominator? Also, if the numerator is
    set to never exceed the denominator, then a large percentage -
    something like 25-50% of the output fractions would equal "1", like
    55/55, 23/23, 7/7, 28/28, and so on.
    I did something like this when using variables;
    var randombot2:Number = Math.ceil(Math.random()* 99);
    var randomtop2:Number = Math.min(randombot2 -
    Math.floor(Math.random()* randombot2* 0.5),
    Math.ceil(Math.random()* 99));
    - but I do not understand how this works in function
    terminology.

  • How can you erase old back up from my external drive which i placed in the trash?

    I removed some old back up from time machine which are on my external drive and it now in the trash. But the old back up is not erasing from my trash can. How can you removed this from the trash without reformatting the external drive.

    You really should not remove any Time Machine backups using that or any other method.
    Go to > Time Machine - Frequently Asked Questions 12 and scroll down to the section in gray at the bottom of the article.
    For more great Time Machine info, see > Apple  OSX  and  Time  Machine  Tips

Maybe you are looking for

  • I have not been able to go to links when in Firefox. When I open the same page in Internet Explorer it works.

    Since I upgraded to the latest Firefox a few days ago I have not been able to access certain links. When I switch to Internet Explore those link work.

  • Firefox crashes when trying to print a certain page

    I process orders placed on our web site. As soon as I updated to v6.0 and then V6.0.1 at a particular page when I need to print out invoices (and only on this page - I print two other pages as well during the processing) firefox crashes when trying t

  • Can't create a pop3 mail account

    i tried search for this topic but there seemed to be no answers.  Hard to believe no one has had this issue.  Just got rid of iPhone and bought a Curve 8310 to last me 3 months when I can tell AT&D to shove their service where the sun don't shine!  A

  • Date to Quarter Conversion

    Hi ,   I need to get the quarter from posting date..   Please let me know the function module to get the quarter from the date. Thanks Vishal

  • Errors in apache logfile

    Hi, Every few seconds the following errors are added to my apache errorlog. File does not exist: d:/ora10gas/apache/apache/htdocs/wi/help/ewer5010.html File does not exist: d:/ora10gas/apache/apache/htdocs/wi/help/ewer50IX.html File does not exist: d