Ok so i have an array of names like this
var names = ["Bob", "Aaron", "John"];
How would i have a line or lines of code that would randomly pick between all 3 of these names and display it? Would i use math.random()?
To generate random text using the current language in a Word document and customize the number of paragraphs and sentences: Position the cursor in the document where you want to generate random text. Type =RAND(number of paragraphs, number of sentences) such as =RAND(3,2). Press Enter.
Since you have a collection of names rather than key value pairs it's better to use an array to store your names rather than a hash.
With an array, you can use Math.floor and Math.random to generate an index to look up in the names array.
names[Math.floor(Math.random() * names.length)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With