Skip to content

Commit

Permalink
Added prng() method
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley committed Jun 2, 2019
1 parent 297551d commit d5ae07f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/api/en/math/Math.html
Expand Up @@ -83,6 +83,9 @@ <h3>[method:Float randFloatSpread]( [param:Float range] )</h3>
<h3>[method:Integer randInt]( [param:Integer low], [param:Integer high] )</h3>
<p>Random integer in the interval [page:Float low] to [page:Float high].</p>

<h3>[method:Float prng]( [param:Integer seed] )</h3>
<p>Deterministic pseudo-random float in the interval [ 0, 1 ]. The integer [page:Integer seed] is optional.</p>

<h3>[method:Float smoothstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
<p>
[page:Float x] - The value to evaluate based on its position between min and max. <br />
Expand Down
5 changes: 5 additions & 0 deletions src/math/Math.d.ts
Expand Up @@ -62,6 +62,11 @@ export namespace _Math {
*/
export function randFloatSpread( range: number ): number;

/**
* Deterministic pseudo-random float in the interval [ 0, 1 ].
*/
export function prng( seed?: number ): number;

export function degToRad( degrees: number ): number;

export function radToDeg( radians: number ): number;
Expand Down
20 changes: 20 additions & 0 deletions src/math/Math.js
Expand Up @@ -117,6 +117,26 @@ var _Math = {

},

// Deterministic pseudo-random float in the interval [ 0, 1 ]

prng: function () {

var seed = 1234567;

return function prng( s ) {

if ( s !== undefined ) seed = s % 2147483647;

// Park-Miller algorithm

seed = seed * 16807 % 2147483647;

return ( seed - 1 ) / 2147483646;

};

}(),

degToRad: function ( degrees ) {

return degrees * _Math.DEG2RAD;
Expand Down

0 comments on commit d5ae07f

Please sign in to comment.