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

  • SEARCH
  • Home
  • 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 8966281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:59:36+00:00 2026-06-15T16:59:36+00:00

Very newbie obj-c question. In ViewController I have four UIImages. They are imitating playing

  • 0

Very newbie obj-c question.

In ViewController I have four UIImages. They are imitating playing cards. User can see only their backside at start. By tapping one of them user will see the front side (animation for this is ready now). My task is to show random front side from four images with defined repetition rate. So I want to set one of the images (prize) will appear eight times less Eight times less than the chance of getting any one of the others, everytime the user will visit this ViewController.

If it’s possible, please show me the piece of code what can generate random but with possibility of setting repetition rate

  • 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-06-15T16:59:37+00:00Added an answer on June 15, 2026 at 4:59 pm
    - (NSUInteger)indexForImageGivenIndexSet:(NSIndexSet*)indexSet             // Set of indexes you want to select from
                             prizeImageIndex:(NSUInteger)prizeIndex      // The prize index
                            probabilityScale:(CGFloat)probabilityScale   // The scale for the prize (8.0 for 8x less than the others)
    {
        // If invalid, return what was given
        if (![indexSet containsIndex:prizeIndex]) {
            return prizeIndex;
        }
    
        // Calculate our probabilities
        // For a set of 4, with a scale of 8 on the prize, our probabilities would be
        // 0.04 (prize), 0.32, 0.32, 0.32
        double prizeProbability = (1.0 / indexSet.count) * (1.0 / probabilityScale);
    
        double val = (double)arc4random() / RAND_MAX;
    
        if (val < prizeProbability) {
            return prizeIndex;
        }
        else {
            // Select from the others in range equally
            NSMutableIndexSet* newSet = [[NSMutableIndexSet alloc] initWithIndexSet:indexSet];
            [newSet removeIndex:prizeIndex];
    
            NSInteger selectedPosition = arc4random() % newSet.count;
            __block NSInteger count = 0;
            return [newSet indexPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
                if (count == selectedPosition) {
                    *stop = YES;
                    return YES;
                }
                else {
                    count++;
                    return NO;
                }
            }];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very newbie question. How can i check that object of model is
quick and very basic newbie question. If i have list of dictionaries looking like
I'm a Ruby newbie. Have a very basic question about static and instance variables.
(very newbie question, please help if you can) how do i connect visual web
This is a very newbie question, and this is something I have done many
Okay, this is probably a very newbie question, but how can I get to
This is a one very newbie question but i just can't figure out where
Probably a very newbie question but, Ive been reading around and have found some
I'm hoping someone can help with this very newbie question. I've just come from
A very simple question but i'm newbie in Java. How can I do the

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.