FuzzyBearBTC/peercoin-walletgenerator — pull request #30 by danbartram (2014-03-12 12:14:57+00:00)
Title: Smoothed out the forceGenerate logic and added updateProgressBar method

### ForceGenerate() Smoothed
Before, if you did not generate all of the required mouse movements/seed points before a time limit, the seeder would simply create two more seed points and consider it done. This means that addresses could be generated with as few as 2 seeds added to the pool.

#### Before
```js
forceGenerate: function () {
// if the mouse has not moved enough
if (ninja.seeder.seedCount < ninja.seeder.seedLimit) {
SecureRandom.seedTime();
ninja.seeder.seedCount = ninja.seeder.seedLimit - 1;
ninja.seeder.seed();
}
}
```

With the new logic, a random time interval (between 10 and 30 milliseconds) is generated and then creates a timer ```ninja.seeder.timer``` to generate new seeds via the ```ninja.seeder.forceGenerateLoop()``` method.

The ```forceGenerateLoop()``` method then adds new seeds on each timer iteration and updates the progress bar, rather than jumping from 0% to 100% in 2 seeds like before; it now ensures that the generated seed count is met.

#### After
```js
forceGenerate: function () {
// if the mouse has not moved enough
if (ninja.seeder.seedCount < ninja.seeder.seedLimit) {
var randomTimeInterval = 10 + Math.floor(Math.random() * 20);
ninja.seeder.timer = setInterval("ninja.seeder.forceGenerateLoop()", randomTimeInterval);
}
},

// Force generating seeds on a timer if the user has not provided enough
// mouse movements
forceGenerateLoop: function() {

ninja.seeder.seed();
ninja.seeder.updateProgressBar();

// Stop if enough seeds have been generated
if (ninja.seeder.seedCount >= ninja.seeder.seedLimit) {
clearInterval(ninja.seeder.timer);
}
}
```

#### Future Improvements
* A more secure/random seed source could be utilized by the ```ninja.seeder.seed()``` method instead of using the current time.
* The timer could be randomized on each iteration so that the time seeds are not incremented evenly on each new iteration.

---

### UpdateProgressBar() Method
Tidied this up a little to be in its own function, rather than spaghetti code.