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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:10:28+00:00 2026-06-04T07:10:28+00:00

Possible Duplicate: Generate unique random numbers in Java I am creating a lottery app

  • 0

Possible Duplicate:
Generate unique random numbers in Java

I am creating a lottery app for android which will generate a set of 6 numbers between 1 and 49. The problem I am having is how can I make these numbers unique.

Random r = new Random();
int n1=r.nextInt(48) + 1;
ball1.setText(String.valueOf(n1));
int n2=r.nextInt(48) + 1;
ball2.setText(String.valueOf(n2));
int n3=r.nextInt(48) + 1;
ball3.setText(String.valueOf(n3));
int n4=r.nextInt(48) + 1;
ball4.setText(String.valueOf(n4));
int n5=r.nextInt(48) + 1;
ball5.setText(String.valueOf(n5));
int n6=r.nextInt(48) + 1;
ball6.setText(String.valueOf(n6));
  • 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-04T07:10:29+00:00Added an answer on June 4, 2026 at 7:10 am

    It’s a very simple solution. You make a for loop which makes new numbers, and if it’s the first number you make, you add it to a temporary array. Then every time you generate a new number, you check with your array of already existing numbers, and then if it’s not unique, you add 1 to the counter of your for loop.

    This will keep going until you have all your unique numbers. Hope that made sense.

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

Sidebar

Related Questions

Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? I'm creating the
Possible Duplicates: Unique (non-repeating) random numbers in O(1)? How do you efficiently generate a
Possible Duplicate: Generating Random Numbers in Objective-C How do I generate a random number
Possible Duplicate: Java: generating random number in a range I want to generate a
Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? I wish to
Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? i want to
Possible Duplicate: Generating random numbers in C using rand to generate a random numbers
Possible Duplicate: Generating random numbers in Javascript Hi.. I want to generate random numbers
Possible Duplicate: How to generate a random String in Java I am wanting to
Possible Duplicate: Javascript/html: How to generate random number between number A and number B?

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.