@esportsplus/random 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ end_of_line = lf
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,8 @@
1
+ declare const float: () => number;
2
+ declare const floats: (n: number) => number[];
3
+ declare const _default: {
4
+ float: () => number;
5
+ floats: (n: number) => number[];
6
+ };
7
+ export default _default;
8
+ export { float, floats };
package/build/index.js ADDED
@@ -0,0 +1,24 @@
1
+ let max = Math.pow(2, 32);
2
+ function browser() {
3
+ return window.crypto.getRandomValues(new Uint32Array(1))[0] / max;
4
+ }
5
+ function node() {
6
+ return require('crypto').randomBytes(4).readUInt32BE(0) / max;
7
+ }
8
+ const float = () => {
9
+ if (globalThis?.crypto) {
10
+ return browser();
11
+ }
12
+ return node();
13
+ };
14
+ const floats = (n) => {
15
+ let i, values = [];
16
+ while (--n > -1) {
17
+ i = Math.floor(Math.random() * (n + 1));
18
+ values[i] = values[n];
19
+ values[n] = float();
20
+ }
21
+ return values;
22
+ };
23
+ export default { float, floats };
24
+ export { float, floats };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "author": "ICJR",
3
+ "description": "Random",
4
+ "devDependencies": {
5
+ "@esportsplus/rspack": "^0.0.1"
6
+ },
7
+ "main": "build/index.js",
8
+ "name": "@esportsplus/random",
9
+ "private": false,
10
+ "scripts": {
11
+ "build": "tsc && tsc-alias",
12
+ "-": "-",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "types": "build/index.d.ts",
17
+ "version": "0.0.1"
18
+ }
package/readme.md ADDED
@@ -0,0 +1,2 @@
1
+ https://github.com/maverick-js/signals
2
+ https://github.com/modderme123/reactively
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ let max = Math.pow(2, 32);
2
+
3
+
4
+ function browser() {
5
+ return window.crypto.getRandomValues(new Uint32Array(1))[0] / max;
6
+ }
7
+
8
+ function node() {
9
+ return require('crypto').randomBytes(4).readUInt32BE(0) / max;
10
+ }
11
+
12
+
13
+ const float = (): number => {
14
+ if (globalThis?.crypto) {
15
+ return browser();
16
+ }
17
+
18
+ return node();
19
+ };
20
+
21
+ // Fisher-Yates shuffle
22
+ // - https://wikipedia.org/wiki/Fisher-Yates_shuffle
23
+ const floats = (n: number): number[] => {
24
+ let i: number,
25
+ values: number[] = [];
26
+
27
+ while(--n > -1) {
28
+ i = Math.floor(Math.random() * (n + 1));
29
+
30
+ values[i] = values[n];
31
+ values[n] = float();
32
+ }
33
+
34
+ return values;
35
+ };
36
+
37
+
38
+ export default { float, floats };
39
+ export { float, floats };
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "declarationDir": "build",
5
+ "outDir": "build",
6
+ },
7
+ "exclude": ["node_modules"],
8
+ "extends": "@esportsplus/rspack/tsconfig.base.json",
9
+ "include": ["src"]
10
+ }