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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:39:29+00:00 2026-06-14T01:39:29+00:00

on the first iteration- I want to create a random number from 0..10 This

  • 0

on the first iteration- I want to create a random number from 0..10

This is how I’ve implement it-

 int generator= (int)(Math.random() * (10));

On the first iteration I want to create another random number, but without one of the values.
For example I would like the random number without the number 4.
only 1,2,3,5,6,7,8,9,0

How can I remove one of the values from the numbers 0..10 when I generate a random number?

  • 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-14T01:39:30+00:00Added an answer on June 14, 2026 at 1:39 am

    1st Way: –

    You can also maintain a List of all the numbers. Then use Collections.shuffle to shuffle the list and get the first element. And remove it.

        List<Integer> list = new ArrayList<Integer>();
    
        list.add(1); 
        list.add(4);
        list.add(2);
        list.add(3);
        System.out.println("Original List: " + list);
    
        Collections.shuffle(list);
    
        System.out.println("Shuffled List: " + list);
        int number1 = list.remove(0);  // Remove the first value
        System.out.println("Number removed: " + number1);
    
        Collections.shuffle(list);
    
        System.out.println("Shuffled List: " + list);
        number1 = list.remove(0);
        System.out.println("Number removed: " + number1);
    

    OUTPUT: –

    Original List: [1, 4, 2, 3]
    Shuffled List: [4, 3, 1, 2]
    Number removed: 4
    Shuffled List: [1, 3, 2]
    Number removed: 1
    

    2nd Way: –

    A better way would be to generate a random number from 0 to the size of the list, and get the value of that index and remove it.

    int size = list.size();
    Random random = new Random();
    
    for (int i = 0; i < size; i++) {    
        int index = random.nextInt(list.size());
        int number1 = list.remove(index);
        System.out.println(number1);
    }
    

    NOTE: –
    If you want to exclude a fixed set of numbers from being generated, then you can have those numbers in a list. And then remove all elements of that list from your list of numbers. And then use any of the approach above.

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

Sidebar

Related Questions

first take a look on this picture from localScope app : i have 2
Given myvector.start() and myvector.end() I want to create a read-only subset of myvector without
So I'm doing a TUI and this was my first iteration. package bulb.classes; import
this is my first time posting on a forum. But I guess I will
I want to create a lookup table in Groovy, given a size (in this
I want to create the jquery image sliders within jsp loop .With this coding
I'm trying to write my first iterator class / container type. Basically, I want
After some recursive function I have an array: first iteration: Array ( [category_id] =>
I have a list of objects of type A. In a first iteration I
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);

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.