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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:08:04+00:00 2026-05-16T15:08:04+00:00

I have 100 values in an array but I need to select 5 value

  • 0

I have 100 values in an array but I need to select 5 value randomly on every click one button and I have one value e.g a=10 this a value shouldn’t come in the 5 selected value.

I tried in different way but I am not able to do it in jquery. please any help me.

  • 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-16T15:08:04+00:00Added an answer on May 16, 2026 at 3:08 pm

    The following code may help. The calculateRandoms function calculates 5 different random numbers from the numbers array each time. The random number cannot be value of excludedNumber. You can change randomCount variable to modify the number of random numbers that calculateRandoms will generate.

    var excludedNumber = 10;
    var randomCount = 5;
    var numbers = [];
    var randoms = [];
    var vPool="";
    
    // initialize array, fill it from 0 to 99
    for (var i = 0; i < 100; i++) numbers.push(i + 1);
    $(document).ready(function() {
        $("#mybutton").click(function() {
            calculateRandoms(randomCount);             
        });
    });
    function calculateRandoms(c) { 
        randoms = [];
        for (var i = 0; i < c; i++) {
            var rnd = excludedNumber;
            while (rnd == excludedNumber && $.inArray(rnd, numbers)){
                rnd = numbers[Math.floor(Math.random() * numbers.length)];
                randoms.push(rnd);
            }
        }
        vPool='';
        $.each(randoms, function(i, val) {  
            vPool+=val + "<br />";
            $("#res").html(vPool);
        });
        //alert(randoms);
        //$("#res").html(randoms);
        //console.log(randoms);
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <input type="button" id="mybutton" value="Generate" />
    <div id="res"></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array with integers of values from 0 to 100. I wish
I need to have an instance of one common object in every other object,
i have a list like this: array( array(id=>100, parentid=>0, name=>'a'), array(id=>101, parentid=>100, name=>'a'), array(id=>102,
I have an input box that takes values from 0-100. I want to prevent
I have to store more than 100 millions of key-values in my HashMultiMap (key
I have to store more than 100 millions of key-values in my HashMultiMap (key
I have to store more than 100 millions of key-values in my HashMultiMap (key
I have a list with these values: ['1', '10', '100.3', '1000.4', '1000.42', '150', '200',
I have a (float) rating value as a percentage from 0..100 (where 50 =
I have a two dimensional array that I need to sort numerically. Here is

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.