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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:08+00:00 2026-05-26T02:41:08+00:00

How to create in Android Java a random number between min and max excluding

  • 0

How to create in Android Java a random number between min and max excluding some numbers that fall between min and max.?

I have three vars, each is a random number between 1-100. I was able to do the random number using the math.rand() but I am trying to make sure that the three numbers do not match. I did a work around using while and if statements, but I was looking to see if there is a one line of command to do this, so that I can put it right under th activity class so that it’s public var. and in that area (activity) I can’t use while and if statements, I only can in onCreate due to the void or something.

Thank you in advance for your help, and will vote for any help or idea that will lead to finding any info about this.

  • 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-26T02:41:08+00:00Added an answer on May 26, 2026 at 2:41 am

    This my AndroidActivity code, and it works.

    package com.androidbook.droid1;
    import java.util.Random;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.TextView;
    public class DroidActivity3 extends Activity
    {
    public static class GetThreeRandomIntClass
    {
        public static class Dots 
        { 
            public int a; 
            public int b; 
            public int c; 
    
            public Dots()
            {
                    a = 0;
                    b = 0;
                    c = 0;
            }
    
            @Override
            public String toString()
            {
                return "[" + a + "]" + "[" + b + "]" + "[" + c + "]";
            }
        }
    
        public static void getThreeRandomInt(Dots d)
        {
            int[] arr = new int[100];
            Random r = new Random();
            for(int i=0; i<arr.length ; i++){
                arr[i] = i + 1;
            }
            int randInt = r.nextInt(100);
            d.a = arr[randInt];
            for(int i=randInt; i<arr.length - 1 ; i++){
                arr[i] = arr[i + 1];
            }
            randInt = r.nextInt(99);
            d.b = arr[randInt];
            for(int i=randInt; i<arr.length - 2 ; i++){
                arr[i] = arr[i + 1];
            }
            randInt = r.nextInt(98);
            d.c = arr[randInt];
        }
    }
    
    
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    
        this.setContentView(R.layout.third);
    
        GetThreeRandomIntClass.Dots d = new GetThreeRandomIntClass.Dots();
        GetThreeRandomIntClass.getThreeRandomInt(d);
    
        TextView textView1 = (TextView) this.findViewById(R.id.textView1);
        textView1.setText(String.valueOf(d.a));
    
        TextView textView2 = (TextView) this.findViewById(R.id.textView2);
        textView2.setText(String.valueOf(d.b));
    
        TextView textView3 = (TextView) this.findViewById(R.id.textView3);
        textView3.setText(String.valueOf(d.c));
    
        super.onCreate(savedInstanceState);
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class that I've written that extends ImageView (for Android Java).
I have some triangle polygons and drawing them in a traditional way: (android-java code)
In Java (Android), is there a way to create a loop that goes through
I am currently trying to create an Android application that loops Audio from the
I am trying to create a simple Android application that has a ActivityList of
For Android GUI: I would like to create a window that I can pull
I'm trying to create an app for Android that simply sends a command to
Is it possible to create an IntentFilter in android that matches ALL intents that
I want to create an application for Android that will be able to scan
I have to create a custom compound button bar control in Android like the

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.