oreillymedia / data_structures_and_algorithms_using_javascript

768 stars 407 forks source link

Chap12.js: function setData() is wrong? #5

Open 404pnf opened 9 years ago

404pnf commented 9 years ago

As you can see from the preceding output, this formula succeeds in generating a set of random numbers between 1 and 10

Math.floor(Math.random() *  (this.numElements+1))

Example code will yield 0 if Math.random returns 0.