Fill list randomly from other lists

HI there. I am a beginner and not quite sure how to approach this (which language to use etc.)… I think this could maybe work with javascript but I’m not sure.

So I have three lists of names, each from a different department. I get those as excel sheets and they contain hundreds of names. What I need to do now is have a simple html table/site where I can enter a number of participants from each department (can be different numbers) and a script will pick that number of random names from the related department-list and put them into one html table. So basically I want to choose let’s say 25 random people from department A, 82 from department B and 37 from department C and list them in one participants list. Is that even possible with javascript? Can I somehow import or convert the excel lists into something javascript can use? Thanks for any hint!

http://learnjsdata.com/read_data.html

You can save your spreadsheet as CSV. The same folder as your JS would be the simplest place to store it.

What you’ll want to do is save each department in its own file, then load all three and convert them to arrays.

An approach selecting might involve,

  • create an empty array
  • shuffle the array so it is not alphabetical
  • use shift or pop to take off as many names as you want from that list and push them to the new array.
  • repeat the above two steps for the other two arrays.

Your new array will contain selections from all three arrays.

Thanks, now I know where and what to look for. I will give it a try. Cheers!

1 Like