// Where 2 is the max random number Math.round(Math.random() * 2) // This will randomly give you 0, 1, or 2
- Node v12.10.0
I was writing a React-Native game where I had multiple cards that would be presented to the player. To spice up the game I would ideally not start on the same card each and every time. I had approximately 100 cards so needed to create a random number from 0-100 to start on a random element of the card array.
// 100 is the max random number that will be returned const card_number = Math.round(Math.random() * 100) // Then I can pull my first element from the card array as follows card_array[card_number]