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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:58:44+00:00 2026-05-24T13:58:44+00:00

I m trying to make a random number generator in android. My code has

  • 0

I m trying to make a random number generator in android. My code has to start generating numbers in sets of 3 after clicking the “generate” button. So far i’ve coded a generator that can produce finite sets of 3 numbers each. What i want to create is a dynamic generator that keeps generating numbers.CODE:
`

public class Plot2Activity extends Activity {  
 /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   final Random myRandom = new Random();

   Button buttonGenerate = (Button)findViewById(R.id.generate);
   final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);

   buttonGenerate.setOnClickListener(new OnClickListener(){

  @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
   ArrayList<Object> Arry1 = new ArrayList<Object>();
    for(int i=0;i<5;i++){
   ArrayList<Integer> Arry = new ArrayList<Integer>();
   for(int k=0;k<3;k++){
       Arry.add(myRandom.nextInt(100));
   }
       Arry1.add(Arry);
   }
       textGenerateNumber.setText(String.valueOf(Arry1));
       }
       });  
    }
 }
  • 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-24T13:58:44+00:00Added an answer on May 24, 2026 at 1:58 pm

    Do the same process in a loop and update an array from a background thread. For background thread look below link this may help you.

    However if you don’t want to generate frequently, Put a sleep() in your background thread for a second and than let it update your Array.

    http://developer.android.com/reference/android/os/AsyncTask.html

    Happy coding,

    Krio

    Article which may help,

    http://www.dailygeek.de/using-asynctask-to-update-a-listactivity/

    Above article shows how you can update your ListActivity in similar fashion you may update your Array.

    Lets say create an activity which has AsycTask, and create a separate class such as,

    public class RandomNumbers{}
    

    Above class will have an Array list of numbers being generated,

    And update this class’s object from Background which eventually available to your UI Thread too. I hope I and clear enough.

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

Sidebar

Related Questions

I am trying to make a Java implementation of the Park-Miller-Carta PRNG random number
I'm trying to generate two random numbers, one for a row and one for
I am trying to generate a random enough number quickly. Right Now I am
I'm trying to make a simple javascript application to pick a random number between
I'm trying to seed a random number generator with the output of a hash.
I'm trying to make a header image change randomly based on a random number
I am trying to generate 5 different random numbers for use in my card
I'm trying to make a simple solitaire in wich you get a random number
I'm trying to make a data bound column invisible after data binding, because it
I am trying to make a JTable that has column spans available. Specifically, I

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.