Math.random regarding paintings


I'm confused about how tables (in Javascript) work in tandem with functions like math.random. Here is an example of the code I would use (I read on several sites that math.random is not the best pseudo-random number generator but it will work for my purposes to understand how math.random selects the variables in the paintings):
 var examples= [1, 2, 3, 56, "foxy", 9999, "jaguar", 5.4, "caveman"]; var example= examples[Math.round(Math.random() * (examples.length-1))]; console.log(example); 
When I put this in the console log, select one of the variables and print it. And since Math.random selects a number greater than or equal to 0 and less than 1, what specific number is assigned to each variable in 'var examples'? Like, what would be the number that would print '1' or '' foxy '' to print?
Does each variable in the array take an equal amount of length greater than or equal to 0 and less than 1? Thanks for the help and sorry if this is poorly formulated or not in the right format.
Math.random regarding paintings Math.random regarding paintings Reviewed by Unknown on February 09, 2018 Rating: 5

No comments:

Powered by Blogger.