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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:53:37+00:00 2026-06-12T15:53:37+00:00

hi im creating a app that generates random text when i press a button

  • 0

hi im creating a app that generates random text when i press a button at the moment i have the code and it works fine but there are some things i would like to change when i run the app and i press the button it shows:

“alright, hiya, yoo, yoo, Hello, alright, Hiya, yoo, yoo, hiya, hello, hello, alright”

thats the first 13 clicks and thats the order every time i go on the app. Basically i dont want them to repeat twice in a row and also i want them to start in different orders when i start the app.

1 more thing i would like to be able to write at least 2 lines of text but how do i do that using a Label?

heres the code i have:

.h

@interface ViewController1 : UIViewController  {

    IBOutlet UILabel *textview;

}

-(IBAction)random;

.m

@interface ViewController1 ()

@end

@implementation ViewController1

-(IBAction)random {

int text = rand() % 5;

switch (text) {

    case 0:

        textview.text = @"Hello";

        break;

    case 1:

        textview.text = @"hi";

        break;

    case 2:

        textview.text = @"alright";

        break;

    case 3:

        textview.text = @"yoo";

        break;

    case 4:

        textview.text = @"hiya";

        break;

    default:

        break;

}

}

thank you 🙂

  • 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-12T15:53:39+00:00Added an answer on June 12, 2026 at 3:53 pm

    Use the function arc4random() instead of random(). The problem you face is because the function rand needs a seed to be set before you call it. This is a starting value for the random number generator used in the background by rand. When you don’t use a own seed it’s always the same default, and you therefore always get the same sequence of random values. When using arc4random there is no need for setting a seed. For further information see this blog post and the documentation.

    #include <stdlib.h>
    ...
    int text = arc4random() % 5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Workflow 4.0 app that generates emails. In a dialog for creating
I'm creating an app that should list the date and time when a button
I'm creating and app that will rely on a database, and I have all
I am creating a WinForm application that basically generates Math worksheets. I know there
I'm creating an app that will have a fair amount of users. Everytime someone
I have an app that generates a docx file base on user input. It
I'm creating a small app in ASP.NET MVC that generates ics (iCal) files based
I have an app that generates a report in a TableLayout with a variable
I am creating an app that will point a simple arrow in the direction
I am creating an app that is a ticket sales system. On the checkout

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.