mercredi 30 septembre 2020

The different options for accessing random elements in an array using JavaScript/P5.js

I am new to using JavaScript and the P5.js library. However, I have many years of experience in Processing and some understanding of Java.

I have worked out 3 ways that I can randomly access an element in an array. All appear to work however I was wondering what would be best practice. `

var cars = ["Saab", "Volvo", "BMW"];

var rm = Math.floor(Math.random() * cars.length); 
var ri = int(random(cars.length));
var words = random(cars);

The first 2 methods are familiar however the 3rd is a new concept, is this somthing that is unique to javaSript.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire