I got this code off here. It selects one of the names at random. All I need is to select more than one name but not repeat any
var textArray = [
"Hello I'm Fred1",
"Hello I'm Jimmy1",
"Hello I'm Terry1",
"Hello I'm Fred2",
"Hello I'm Jimmy2",
"Hello I'm Terry2",
"Hello I'm Fred3",
"Hello I'm Jimmy3",
"Hello I'm Terry3"
];
var randomNumber = Math.floor(Math.random() * textArray.length);
document.getElementById("randomNumber").innerHTML = textArray[randomNumber];
<p id="randomNumber"> </p>
I can’t figure it out
2
Answers
Just randomly splice from the array’s shallow copy:
One way to do it:
Generate three random indices for selecting lines.
Select the lines at the random indices
Join the selected lines into a single string with line breaks