• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomize a List - is this possible?

Community Beginner ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

I want to create a fillable form  as a sign up list of players.  After gathering X number of players, I would like to randomize as follows:

Sign ups:

Player 1 - Ann

Player 2 - Bob

Player 3 - Carl

 

(then, I assume, a button to iniiate randomizing the above with the results below:)

 

Randomize List:

Player 1 - Carl

Player 2 - Ann

Player 3 - Bob

 

Hopefully, the above example explains my desire.  Is this possible?  I can do it in Excel, but would like a fillable form application to to it.  Suggestions?

Thank you in advance.

TOPICS
How to , JavaScript , PDF forms

Views

459

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2021 Feb 25, 2021

Try this code:

 

var maxFields = 4;
var values = [];
for (var i=1; i<=maxFields; i++) {
	var v = this.getField("Text"+i).valueAsString;
	if (v!="") values.push(v);
}

var newValues = [];
var usedIndexes = [];
while (newValues.length<values.length) {
	var randomIdx = Math.floor(Math.random()*values.length);
	while (usedIndexes.indexOf(randomIdx)!=-1)
		randomIdx = Math.floor(Math.random()*values.length);
	newValues.push(values[randomIdx]);	
	usedIndexes.push(randomIdx);
}

for (var i=1; i<=maxFie
...

Votes

Translate

Translate
Enthusiast ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

How do you enter names?

You want to show random names in list box?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Sign ups via a fillable list of text boxes #1 through #4 for a team doubles tournament.

 

By randomizing players, the partner selection will also become randomized, thus insuring the competitions

aren't stacked in favor os those working the system.  Hope that makes sense.

The below schedule is set and won't change.  I want to alleviate players choosing which slot they may fill.

 

Round 1

#1 & #2  -v-  #3 & #4

Round 2

#1 & #3  -v-  #2 & #4

Round 3

#1 & #4  -v-  #2 & #3

 

For this example, what I envision is four text bozex for the player snames to be entered.  A button that will initiate a scripot to randomize, then the results to be displayed as above with player names instean of numbers.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

I apologize for the "fat finger" spelling mistakes above.  I have little experience with Javascript and really don't know if this is even possible.  Just asking.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Try this code:

 

var maxFields = 4;
var values = [];
for (var i=1; i<=maxFields; i++) {
	var v = this.getField("Text"+i).valueAsString;
	if (v!="") values.push(v);
}

var newValues = [];
var usedIndexes = [];
while (newValues.length<values.length) {
	var randomIdx = Math.floor(Math.random()*values.length);
	while (usedIndexes.indexOf(randomIdx)!=-1)
		randomIdx = Math.floor(Math.random()*values.length);
	newValues.push(values[randomIdx]);	
	usedIndexes.push(randomIdx);
}

for (var i=1; i<=maxFields; i++) {
	if (i<=newValues.length) this.getField("Text"+i).value = newValues[i-1];
	else this.getField("Text"+i).value = "";
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

Where does this code go though..? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

LATEST

You can use it in a button as 'Mouse UP' action.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines