Skip to content

Commit

Permalink
replace mulberry with splitmix32, fixes StoneCypher/fsl#1250
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Oct 25, 2023
1 parent e1ef14c commit 1401a08
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 39 deletions.
17 changes: 16 additions & 1 deletion src/doc_md/CHANGELOG.long.md
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

1097 merges; 186 releases
1098 merges; 186 releases



Expand All @@ -18,6 +18,21 @@ Published tags:



 

 

## [Untagged] - 10/25/2023 10:58:24 AM

Commit [e1ef14c5268547a18010d378267f7196e186a08c](https://github.com/StoneCypher/jssm/commit/e1ef14c5268547a18010d378267f7196e186a08c)

Author: `John Haugeland <stonecypher@gmail.com>`

* silence most build warnings




&nbsp;

&nbsp;
Expand Down
36 changes: 17 additions & 19 deletions src/doc_md/CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

1097 merges; 186 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
1098 merges; 186 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)



Expand All @@ -18,6 +18,21 @@ Published tags:



&nbsp;

&nbsp;

## [Untagged] - 10/25/2023 10:58:24 AM

Commit [e1ef14c5268547a18010d378267f7196e186a08c](https://github.com/StoneCypher/jssm/commit/e1ef14c5268547a18010d378267f7196e186a08c)

Author: `John Haugeland <stonecypher@gmail.com>`

* silence most build warnings




&nbsp;

&nbsp;
Expand Down Expand Up @@ -174,21 +189,4 @@ updated-dependencies:
- dependency-name: xml2js
dependency-type: direct:development
...
* Signed-off-by: dependabot[bot] <support@github.com>




&nbsp;

&nbsp;

<a name="5__88__4" />

## [5.88.4] - 2/7/2023 3:52:11 PM

Commit [ef4285a2699696409cfd36f3ed5b63f67f568f34](https://github.com/StoneCypher/jssm/commit/ef4285a2699696409cfd36f3ed5b63f67f568f34)

Author: `John Haugeland <stonecypher@gmail.com>`

* cleanup and bumps
* Signed-off-by: dependabot[bot] <support@github.com>
35 changes: 24 additions & 11 deletions src/ts/jssm_util.ts
Expand Up @@ -199,25 +199,36 @@ const named_hook_name = (from: string, to: string, action: string): string =>

/*******
*
* Creates a Mulberry32 random generator. Used by the randomness test suite.
* Creates a SplitMix32 random generator. Used by the randomness test suite.
*
* Sourced from `bryc` at StackOverflow: https://stackoverflow.com/a/47593316/763127
* Sourced from `bryc`: https://github.com/bryc/code/blob/master/jshash/PRNGs.md#splitmix32
*
* Replaces the Mulberry generator, which was found to have problems
*
*/

const make_mulberry_rand = (a?: number | undefined) =>
function gen_splitmix32(a? : number | undefined) {

() => {
if (a === undefined) {
a = new Date().getTime();
}

if (a === undefined) { a = new Date().getTime(); }
return function() {

let t = a += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
a |= 0;
a = a + 0x9e3779b9 | 0;

return ((t ^ t >>> 14) >>> 0) / 4294967296;
var t = a ^ a >>> 16;
t = Math.imul(t, 0x21f0aaad);

};
t = t ^ t >>> 15;
t = Math.imul(t, 0x735a2d97);

return ((t = t ^ t >>> 15) >>> 0) / 4294967296;

}

}



Expand Down Expand Up @@ -306,13 +317,15 @@ function find_repeated<T>(arr: T[]): [T, number][] {


export {

seq,
unique, find_repeated,
arr_uniq_p,
histograph, weighted_histo_key,
weighted_rand_select, weighted_sample_select,
array_box_if_string,
name_bind_prop_and_state, hook_name, named_hook_name,
make_mulberry_rand
gen_splitmix32

};

12 changes: 6 additions & 6 deletions src/ts/tests/util.spec.ts
Expand Up @@ -3,7 +3,7 @@ import {
seq,
unique,
find_repeated,
make_mulberry_rand,
gen_splitmix32,
name_bind_prop_and_state
} from '../jssm_util';

Expand Down Expand Up @@ -82,15 +82,15 @@ describe('seq', () => {



describe('make_mulberry_rand', () => {
describe('gen_splitmix32', () => {



seq(3).map(n =>

test(`Seed ${n} - Generates 500 numbers [0,1)`, () => {

const rnd = make_mulberry_rand(n);
const rnd = gen_splitmix32(n);
let fail = false;

seq(500).forEach(_ => {
Expand All @@ -111,13 +111,13 @@ describe('make_mulberry_rand', () => {



const rnd = (n) => Math.floor(make_mulberry_rand( new Date().getTime()+n )() * Number.MAX_SAFE_INTEGER );
const rnd = (n) => Math.floor(gen_splitmix32( new Date().getTime()+n )() * Number.MAX_SAFE_INTEGER );

[ rnd(0), rnd(1), rnd(2), rnd(3), rnd(4) ].map( n =>

test(`Seed ${n} - Generates 500 numbers [0,1)`, () => {

const rnd = make_mulberry_rand(n);
const rnd = gen_splitmix32(n);
let fail = false;

seq(500).forEach(_ => {
Expand All @@ -140,7 +140,7 @@ describe('make_mulberry_rand', () => {

test(`Seed undefined - Generates 500 numbers [0,1)`, () => {

const rnd = make_mulberry_rand();
const rnd = gen_splitmix32();
let fail = false;

seq(500).forEach(_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/version.ts
@@ -1,5 +1,5 @@

const version : string = "5.89.3",
build_time : number = 1698256594220;
const version : string = "5.89.4",
build_time : number = 1698257988350;

export { version, build_time };

0 comments on commit 1401a08

Please sign in to comment.