DEV Community

chaderenyore
chaderenyore

Posted on

Is it Possible to create a random number with values from an Array?

Yeah it is very possible to do what you're asking

const diceRoll = Array.from({ length: 100 }, (_, i) => {
return i + 1
});

console.log(Math.random() * diceRoll.length);

The code there, why it works is that Math.random returns a random number between 0 and whatever value we set and…

Top comments (0)