I'm trying to get a random amount of items from an array.
This is what I've got so far:
I'm calling the function (in another part of a long code) with the min and max values:
generateitems(1,7)
And this is the rest:
function generateitems(min, max) {
var myArray = ["aa","bb","cc","dd","ee","ff","gg"];
var randomItem = myArray[Math.floor(Math.random()* (max - min)) + min];
return randomItem;
}
I keep just getting one item as a result. How do I fix this?
I know how to generate one/a specific amount, or all of the items from the array, and my program works when I do that -- so I don't think there's an issue with the rest of my code. I just can't figure out how to use Math.random here, or if it's even the right thing to use in this case.
Thank you for your time.
EDIT:
wanted result:
the function should return 1-7 items
duplicates are ok, I don't care about the order of the items