Last active
April 9, 2023 16:09
-
-
Save VityaSchel/9e73ed371371d1c3baae4de0a33b22d7 to your computer and use it in GitHub Desktop.
Revisions
-
VityaSchel revised this gist
Apr 9, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ function testingRandom(func, limitChecks = 10000) { let maxSymbols = stringOfSymbols.length for(let [k, v] of Object.entries(ordered)) { let timesOfSymbol = (v*maxSymbols)/maxOfValues visual+=k+' '+stringOfSymbols.substring(0,timesOfSymbol)+' ('+(v/limitChecks*100)+'%)\n' } console.log(visual) return ordered -
VityaSchel created this gist
May 6, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ /* RANGE VISUALIZER BY VITYASCHEL This script is useful when you want to check equality of random results. Run testingRandom with function and limit of checks More checks = more accurate Example: testingRandom(() => Math.random().toFixed(1), 10000) Output: 0.0 ********* 0.1 ******************* 0.2 ******************* 0.3 ****************** 0.4 ******************** 0.5 ******************* 0.6 ******************* 0.7 ****************** 0.8 ******************* 0.9 ******************* 1.0 ********* */ function testingRandom(func, limitChecks = 10000) { let objSrc = {} for (let i = 0; i < limitChecks; i++){ let res = func() let count = objSrc[res] if(count === undefined) count = 0 objSrc[res] = count+1 } let ordered = Object.keys(objSrc).sort().reduce( (obj, key) => { obj[key] = objSrc[key]; return obj }, {} ) let visual = "" let maxOfValues = Math.max(...Object.values(ordered)) let stringOfSymbols = '********************' let maxSymbols = stringOfSymbols.length for(let [k, v] of Object.entries(ordered)) { let timesOfSymbol = (v*maxSymbols)/maxOfValues visual+=k+' '+stringOfSymbols.substring(0,timesOfSymbol)+'\n' } console.log(visual) return ordered }