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 1087725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:58:32+00:00 2026-05-16T22:58:32+00:00

how can an array be created that randomizes results from 3 different values 0,1,2

  • 0

how can an array be created that randomizes results from 3 different values 0,1,2 and then makes 2 combinations of those

for example :
i have

int values[3] = {0,1,2}
blah = values[arc4random() %3];

i tried using this from the arc4random help post on this site however when i do the above the app crashes. Im a begginer to arc4random and cant figure a solution to this since there isnt enough documents online to help me.
Furthermore how can i choose 2 items from blah to be displayed?

  • 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-16T22:58:33+00:00Added an answer on May 16, 2026 at 10:58 pm

    Well, for one you’re missing a ;

    int values[3] = {0,1,2}; //<-- here
    int blah = values[arc4random() %3];
    NSLog(@"Value: %d",blah);
    

    Second, the above compiles just fine.

    Third, I think you want to do this, but as @Shaggy Frog mentioned, your question is kindof unclear:

    int combo[3];
    for (int i = 0; i < 3; i++) {
        combo[i] = values[arc4random() %3];
    }
    

    Which should give you a random “combination” of the values in values[]. Combination has a specific definition, as well as permutation.

    I believe what you want is a set of 3 numbers chosen at random from values[]. If you do need permutations, get comfy with Dijkstra.


    [Edit]

    To get what you specified in the comment, you can do this:

    int values[3] = {0,1,2}; 
    int sum;
    switch (arc4random()%3) {
    case 0:
        sum = values[1] + values[2];
        break;
    case 1:
        sum = values[0] + values[2];
        break;
    case 2:
        sum = values[1] + values[0];
        break;
    }
    

    [Edit]

    Or, you can do this:

    int values[3] = {0,1,2}; 
    int blah[2];
    int index;
    switch (arc4random()%3) {
    case 0:
        index = arc4random()%2;
        blah[index] = values[1];
        blah[1-index] = values[2];
        break;
    case 1:
        index = arc4random()%2;
        blah[index] = values[0];
        blah[1-index] = values[2];
        break;
    case 2:
        index = arc4random()%2;
        blah[index] = values[1];
        blah[1-index] = values[0];
        break;
    }
    

    a card drawing algorithm may also suit your needs.

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

Sidebar

Related Questions

A PHP array can have arrays for its elements. And those arrays can have
In PHP I can name my array indices so that I may have something
I'm using a UITableView to show some data from an array. This array can
How can I create an array of email addresses contained within a block of
How can I create an empty one-dimensional string array?
You can initialize an array like this: int [ ] arr = { 1,
Can jQuery test an array for the presence of an object (either as part
How can i convert an array of bitmaps into a brand new image of
How can I initialize a const / static array of structs as clearly as
I'm trying to access a getJson array I created to add image references to

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.