Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:12:05+00:00 2026-05-25T00:12:05+00:00

I have two methods, the generateRandomCard method gets called within the testMethod, where there

  • 0

I have two methods, the generateRandomCard method gets called within the testMethod, where there is a for loop that runs 100 times. That way it works perfect, but if I set the for loop limit to 1000 or any other number greater than 100 it crashes. Can you see what’s wrong??

- (void)testMethod {

    Globals *myGlobals = [Globals sharedInstance];
    int rankOfFirst = 0;
    int rankOfSecond = 0;
    int playerOneWin = 0;
    int playerTwoWin = 0;
    int ties = 0;
    float firstPercent = 0;
    float secondPercent = 0;
    float tiePercent = 0;
    FiveEval *evaluator = [FiveEval theEvaluator];

    for (int i = 0; i < 100; i++) {
        short fPF = [self generateRandomCard];
        short fPS = [self generateRandomCard];
        short sPF = [self generateRandomCard];
        short sPS = [self generateRandomCard];
        short fFlop = [self generateRandomCard];
        short sFlop = [self generateRandomCard];
        short tFlop = [self generateRandomCard];
        short tur = [self generateRandomCard];
        short riv = [self generateRandomCard];

        rankOfFirst = [evaluator getRankOfSeven:fFlop 
                                               :sFlop 
                                               :tFlop
                                               :tur 
                                               :riv 
                                               :fPF 
                                               :fPS];

        rankOfSecond = [evaluator getRankOfSeven:fFlop 
                                             :sFlop 
                                             :tFlop 
                                             :tur 
                                             :riv 
                                             :sPF 
                                             :sPS];

        if (rankOfFirst > rankOfSecond) {
            playerOneWin++;
        } else if (rankOfSecond > rankOfFirst) {
            playerTwoWin++;
        } else {
            ties++;
        }

        [myGlobals.alreadyPickedCards removeAllObjects];
    }

    firstPercent = ((float)playerOneWin/(float)10000)*100;
    secondPercent = ((float)playerTwoWin/(float)10000)*100;
    tiePercent = ((float)ties/(float)10000)*100;

    NSLog(@"First Player Equity: %f", firstPercent);
    NSLog(@"Second Player Equity: %f", secondPercent);
    NSLog(@"Tie Equity: %f", tiePercent);
}


- (short)generateRandomCard {

    Globals *myGlobals = [Globals sharedInstance];
    short i = arc4random()%51;
    for (int j = 0; j < [myGlobals.alreadyPickedCards count]; j++) {
        if (i == [[myGlobals.alreadyPickedCards objectAtIndex:j] shortValue]) {
            [self generateRandomCard];
        }
    }
    [myGlobals.alreadyPickedCards addObject:[NSNumber numberWithShort:i]];
    return i;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:12:06+00:00Added an answer on May 25, 2026 at 12:12 am

    You’re probably overflowing your stack in the recursive call to -generateRandomCard. If you generate a card that’s already been picked, you call yourself recursively (and ignore the result, which is a different bug). So, if your random number stream gave you an unlucky sequence that kept returning cards you’ve already picked, then you’ll recurse infinitely until the stack overflows.

    Change your card selection algorithm so that instead of using rejection sampling with the potential for infinite looping/recursion, it uses an algorithm with a bounded runtime such as the Fisher-Yates shuffle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple class with two methods; One that will be called
I have two methods below. One method ( timerHit ) which gets the track
i have two methods New() and Edit() and another method make() that has some
I have two webservices that have exactly the same methods and signatures but point
I have a class that contains two methods like these: public String getFoo(Int32 a)
I have two methods that I'm using as custom tags in a template engine:
I have two methods that basically converts underlying checkboxes' text or tag as CSV
I have two methods in C# 3.5 that are identical bar one function call,
I have two methods that are overloads of each other public class Car {
I have two methods with the following signatures void Invoke(Action method) void Foo() What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.