typescript-dotnet-core
Version:
A the core classes and utilities of a JavaScript-Friendly .NET Based TypeScript Library.
7 lines (6 loc) • 1.45 kB
JavaScript
;
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET-Core/blob/master/LICENSE.md
*/Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),SimpleEnumeratorBase_1=require("./SimpleEnumeratorBase"),Enumerator_1=require("./Enumerator"),Randomizer=function(o){function e(e,t){void 0===t&&(t=!1);var r=o.call(this)||this;return r._allowReset=t,r._buffer=Enumerator_1.toArray(e),r._pointer=r._buffer.length,r}return tslib_1.__extends(e,o),e.prototype._canMoveNext=function(){var e=this._pointer;return!isNaN(e)&&0<e},e.prototype.moveNext=function(){var e=this;if(e._canMoveNext()){var t=this._pointer,r=Math.floor(Math.random()*t),o=this._buffer,n=o[r],i=t-1;return o[r]=o[i],o[i]=null,this._allowReset||i%32!=0||(o.length=i),this._pointer=i,e._current=n,e.incrementIndex(),!0}return!1},e.prototype.reset=function(){if(!this._allowReset)throw"Reset not allowed. To allow for reset, specify so when constructing.";if(!this._buffer)throw"Randomizer cannot be reset. Already disposed.";this._pointer=this._buffer.length,o.prototype.reset.call(this)},e.prototype.dispose=function(){o.prototype.reset.call(this);var e=this._buffer;this._buffer=null,this._pointer=NaN,e&&(e.length=0)},e.prototype.getIsEndless=function(){return!1},e}(SimpleEnumeratorBase_1.default);exports.Randomizer=Randomizer;
//# sourceMappingURL=Randomizer.js.map