Skip to content

Commit

Permalink
fixed seed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Dec 30, 2015
1 parent c0b8622 commit 9759c8d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions randomColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@

options = options || {};

if (options.seed && !seed) {
// Check if there is a seed and ensure it's an
// integer. Otherwise, reset the seed value.
if (options.seed && options.seed === parseInt(options.seed, 10)) {
seed = options.seed;

// Something was passed as a seed but it wasn't an integer
} else if (options.seed !== undefined && options.seed !== null) {
throw new TypeError('The seed value must be an integer');

// No seed, reset the value outside.
} else {
seed = null;
}

var H,S,B;
Expand All @@ -53,18 +63,17 @@
options.count = null;

while (totalColors > colors.length) {

// Since we're generating multiple colors,
// incremement the seed. Otherwise we'd just
// generate the same color each time...
if (seed && options.seed) options.seed += 1;

colors.push(randomColor(options));
}

options.count = totalColors;

//Keep the seed constant between runs.
if (options.seed && totalColors !== colors.length) {
seed = options.seed;
} else {
seed = null;
}

return colors;
}

Expand Down

0 comments on commit 9759c8d

Please sign in to comment.