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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:41:43+00:00 2026-05-16T07:41:43+00:00

What I am trying to do is create a an array of text strings,

  • 0

What I am trying to do is create a an array of text strings, and I want to select a random text string out of this array, which I could normally do easily with an array. However, I would also like to be able to put them into categories, and when I select a random one, I would like to know what category it is in and do something different with it which is decided by the category it was in. I was thinking I could use keys in NSDictionary to decide the categories as in setting all the entries in a category to have the same key. But then I don’t know how I could retrieve a random one from that dictionary and then know what the key was. I have never used NSDictionary so I don’t know much about it so maybe what I just said doesn’t make any sense.

It is also possible that I am approaching this in completely the wrong way, so if you have any other suggestions as to how to do what I described I would be open to that, and a pretty detailed code answer would be best if it is possible.

  • 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-16T07:41:43+00:00Added an answer on May 16, 2026 at 7:41 am

    I would just fill the array with dictionaries, i.e.

    {
      { category = Animals,
        name = Cat },
      { category = Vehicles,
        name = Helicopter },
      { category = Foods
        name = Pie },
      { category = Animals,
        name = Zebra }
    }

    and then select randomly from that array.

    For a programmatic example:

    theArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"Animals", @"category", @"Cat", @"name", nil],
                                         [NSDictionary dictionaryWithObjectsAndKeys:@"Vehicles", @"category", @"Helicopter", @"name", nil],
                                         // ...
                                         [NSDictionary dictionaryWithObjectsAndKeys:@"Animals", @"category", @"Zebra", @"name", nil],
                                         nil];
    
    // ...
    
    randomDict = [theArray objectAtIndex:(rand() % [theArray count])];
    NSString *name = [randomDict objectForKey:@"name"];
    NSString *category = [randomDict objectForKey:@"category"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to take a string of text and create an array from
I am trying to create an array of product SKU's which I can then
I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I'm trying to create a 2D array in XNA which I'll be using as
I'm trying to create a program that reads this text file with a list
I am trying to create a 2d array using the contents of a text
I am trying to create a md5 string from the byte array of an
I am trying to create a table from a 2-D array of strings. However,
I'm trying to use this example to create a program which will list all

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.