I want to create a lists of items where the items are selected at random with each item selected from a different group. I'm very new at this, but this code seems to do that.
<html>
<body>
<p>Random items from three different groups:</p>
<script type="text/javascript">
<!--
document.write('<ol>');
// first group
var first_group = new Array ();
first_group[0] = "one";
first_group[1] = "two";
first_group[2] = "three";
var i = Math.floor(3*Math.random())
document.write('<li>' + first_group[i]);
// second group
var second_group = new Array ();
second_group[0] = "three";
second_group[1] = "four";
second_group[2] = "five";
var i = Math.floor(3*Math.random())
document.write('<li>' + second_group[i]);
// third group
var third_group = new Array ();
third_group[0] = "five";
third_group[1] = "six";
third_group[2] = "seven";
var i = Math.floor(3*Math.random())
document.write('<li>' + third_group[i]);
document.write('</ol>');
//-->
</script>
</body>
</html>
Is it possible to modify the code so that even though the same items occur in multiple groups, the same item can't appear more than once in the final list? (For example, if "three" is selected from the first group, it can't be selected from the second.) And is it possible to have the final list in a random order? Any suggestions for other improvements are welcome too.