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

The Archive Base Latest Questions

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

I can create random numbers from a range using Random rand = new Random();

  • 0

I can create random numbers from a range using

Random rand = new Random();
int num = rand.nextInt(10);
System.out.println("Generated Random Number between 0 to 10 is : " + num);

But if i need the next random number generated to be a part of the range minus the already generated one, will keeping the above statement in a loop will suffice?

Also I need to stop once i exhaust all the number from the range.

For eg,

The code gives me a random number between [0-10],

1st - 4 – range {[0-10]}

2nd - 9 – range {[0-10]-4}

3rd - 8 – range {[0-10]-4,9}

..

..

10th - 10 – range {[0-10]-[0-9]}

Will this function output from [Range]{this is my requirement} or (Range)? Or is there any better alternative solution?

  • 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-15T04:47:32+00:00Added an answer on June 15, 2026 at 4:47 am

    The easiest way would probably be to:

    • put the numbers (0 to 10) in a list
    • call Collections.shuffle() on that list
    • loop over the list

    Something like:

    List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10);
    Collections.shuffle(numbers);
    System.out.println(numbers);
    

    You can even provide a random generator for the shuffling operation if the default doesn’t suit you.

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

Sidebar

Related Questions

How can I create an array with 40 elements, with random values from 0
How can create a New user in ORACLE with full access (alter, delete, select,
I can create a sparse php array (or map) using the command: $myarray =
I want to generate unique and random numbers or IDs which I can use
Is there a difference between generating multiple numbers using a single random number generator
on the first iteration- I want to create a random number from 0..10 This
I am writing a program where there are worker threads which create random numbers
I can create and use dynamic two dimensional array in Fortran (in 77 standard).
You can create a table model and add it to a table TableModel tm
How can create a string in JSON after a mysql select: $ritorno = '{Prodotto:'.$riga['Prodotto'].',Prezzo:'.$riga['Prezzo'].'}'

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.