JS achieves randomly extracting three people

Because the laboratory needs three people to do report, use JS to make a randomly extracted page.

First, let’s talk about the needs. 5 people in the second classmates, one person is a separate group, and 9 people have a total of 9 people, and nine people are divided into three groups. Therefore, eight groups, the three reported three people were extracted from eight groups, and these three could not have two or more people in the same group.

1. Three groups of three groups will be built into three small arrays, and one is randomly extracted from each group in these three arrays;

2. Place the five people and the five people drawn in the first step, form a new array, randomly extract three people;
3. If the three people randomly extracted, there is the above situation, then Returns to the first step, randomly extract until there is no second step, then output;

Procedure 2

Put the laboratory owner in one In the large array, I will randomly extract three people from the array;

will build three small arrays in the three groups, and the randomly extracted three people will be circulated to determine if there are two or more people in the same group.


I originally thought that the idea was better, and it was found that it was found that the same group was again re-enabled, and there was always a problem. The three people judged through the for loop, but they could not be realized, and I still need to think about it. The idea is as follows

FOR (var i = 0; i
 ";} flag = false; newArray = [];}}}  <3;i++) {
  index1 = Math.round(Math.random()*(array.length-1));
  value = array[index1];


  value ='';

 for (var j =0;j<newarray.length;j++) {
  for (var m = 0; m < arr1.length; m++) {
   if (newarray[j] === arr1[m]){
  for (var n = 0; n < arr2.length; n++) {
   if (newarray[j] === arr2[n]){
  for (var o = 0; o < arr3.length; o++) {
   if (newarray[j] === arr3[o]){
 btn.onclick = function (){

 var id = setInterval(frame,500);
 function frame() {
  if (!flag) {
  } else {
   for (var i = 0; i < newarray.length; i++) {
    document.getElementById("name").innerHTML += newarray[i] + "
there is still some problems, ideas two can be normally implemented, the following is the idea two procedures:

function Begin () { Num1 = math.Round (Math.random) * (Arr4.Length – 1)); Num2 = math.Round (math.random () * (Arr4.Length – 1)); Num3 = math.Round (Math.random () * (Arr4.length – 1 ); Begin2 ();} function begin2 () {var array = []; var arraylast = []; if (Num1! == Num2 && num1! == Num3 && num2! == Num3) {Array.push (ARRAY.PUSH Num1); Array.push (Num2); Array.push (NUM3); for (var i = 0; i
 ";}} btn.onclick = function ()} ();}  < array.length; i++) {
    if (typeof arr4[array[i]] === "string") {
    } else {
     var num4 = Math.round(Math.random() * (arr4[array[i]].length - 1));
  } else {

  for (var i = 0; i < arrayLast.length; i++) {
   document.getElementById("name").innerHTML += arrayLast[i] + "
The above is all the content of this article, I hope to help everyone, and I hope everyone will support Tumi Cloud.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment