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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:31:19+00:00 2026-06-06T04:31:19+00:00

I am trying to use arc4random but it os causing my app to crash.

  • 0

I am trying to use arc4random but it os causing my app to crash. On my view I have a text field and the user will enter a number, when the hit a button this number is used for the range, the code I use is as follows:

int myInt1 = [textfield.text intValue];
int fromNumber = 1;

int rnumber = (arc4random() % (myInt1 - fromNumber)) + fromNumber;
number1.text = [[NSString alloc] initWithFormat:@"%i",rnumber];

It will work if I use 50 for example instead of myInt1 but I need the user input. Any help is greatly appreciated.

I have noticed that it will work when there is a figure in the textfield, when this is left blank and the button is selected then the app crashed. In the console “Terminating in response to SpringBoard’s termination” is 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-06-06T04:31:20+00:00Added an answer on June 6, 2026 at 4:31 am

    If the variable 50 is working then there is obviously something wrong with your text field’s text. Most likely your text field is nil. Try checking back to your code and see if anything is influencing your app to become nil.

    I will tell you this in case something similar happens next time. You should always try to debug your code, for example, instead of straight posting this to stack overflow with minimal code, try figuring out the problem yourself!

    For example, a method identify what is wrong with your problem that I suggest you try now and feedback the results to me is checking if textfield is non-zero like below:

    if (textfield) {
    
     NSLog (@"Text field is not nil! GOOD!");
    
     }
    

    If the log is called in your console, you know your problem is that textfield is nil.

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

Sidebar

Related Questions

Hi I'm trying use a datepicker on a field I have. I'm trying to
I am trying use Thread but i have some problem (I am beginner at
Trying to use Java's regexp I want to match /app, /app/.* , but not
Im trying use a Java annotation in a Groovy class but have trouble to
I am trying use a Java Uploader in a ROR app (for its ease
I have been trying use the edit_post_link() function to contain an image. All of
I'm a little confused here, I am trying use a partial view in a
I am trying use filehelpers class builder but I am kinda confused on what
I was trying use svn to find a checkin using svn log, but it
I am trying use std::copy to copy from two different iterator. But during course

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.