แก้วงเล็บ

This commit is contained in:
Pitchaya Boonsarngsuk
2018-03-22 15:48:30 +00:00
parent d31951fa85
commit f316d2755a
3 changed files with 6 additions and 6 deletions

View File

@@ -24,10 +24,10 @@ export function takeSampleFrom(sourceList, amount) {
} }
for (let i = 0; i < amount; ++i) { for (let i = 0; i < amount; ++i) {
let rand = sourceList[Math.floor((Math.random() * max))]; let rand = sourceList[Math.floor(Math.random() * max)];
// Re-random until suitable value is found. // Re-random until suitable value is found.
while (randElements.includes(rand)) { while (randElements.includes(rand)) {
rand = sourceList[Math.floor((Math.random() * max))]; rand = sourceList[Math.floor(Math.random() * max)];
} }
randElements.push(rand); randElements.push(rand);
} }

View File

@@ -126,10 +126,10 @@ export default function () {
break; break;
} }
let rand = Math.floor((Math.random() * max)); let rand = Math.floor(Math.random() * max);
// Re-random until suitable value is found. // Re-random until suitable value is found.
while (randElements.includes(rand) || exclude.includes(rand)) { while (randElements.includes(rand) || exclude.includes(rand)) {
rand = Math.floor((Math.random() * max)); rand = Math.floor(Math.random() * max);
} }
randElements.push(rand); randElements.push(rand);
} }

View File

@@ -52,7 +52,7 @@ export default function() {
let u = 2 * Math.random() - 1; let u = 2 * Math.random() - 1;
let v = 2 * Math.random() - 1; let v = 2 * Math.random() - 1;
let r = u * u + v * v; let r = u * u + v * v;
if (r == 0 || r > 1) return gaussRandom(); if (r == 0 || r > 1) {return gaussRandom();}
return u * Math.sqrt(-2 * Math.log(r) / r); return u * Math.sqrt(-2 * Math.log(r) / r);
} }
@@ -74,7 +74,7 @@ export default function() {
* @return {Float64Array} - array of zeros with length n. * @return {Float64Array} - array of zeros with length n.
*/ */
function zeros(n) { function zeros(n) {
if (typeof(n) === 'undefined' || isNaN(n)) { if (typeof n === 'undefined' || isNaN(n)) {
return []; return [];
} }
return new Float64Array(n); // typed arrays are faster return new Float64Array(n); // typed arrays are faster