.random possible?
NightScript370 opened this issue · 1 comments
NightScript370 commented
How would I go about making a .random function that would allow me to get a random value of the list? I can do it for normal arrays but I'm not sure how to do it for list.
Normal array Random code:
Array.prototype.random = function() {
return this[Math.floor(Math.random() * this.length)];
};
paldepind commented
Hi @NightYoshi370.
Why did you close the issue?
This should work:
function random(list) {
return list.nth(Math.floor(Math.random() * list.length));
};
The code list.nth(n)
is equivalent to array[n]
.
I hope that helps 😄