@fgv/ts-random 5.1.0-8

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.
Files changed (254) hide show
  1. package/config/jest.config.json +13 -0
  2. package/config/rig.json +4 -0
  3. package/config/typedoc.json +7 -0
  4. package/docs/Chars/README.md +152 -0
  5. package/docs/Chars/variables/all.md +9 -0
  6. package/docs/Chars/variables/alphanumeric.md +9 -0
  7. package/docs/Chars/variables/base64.md +9 -0
  8. package/docs/Chars/variables/base64Url.md +9 -0
  9. package/docs/Chars/variables/base64UrlNoPadding.md +9 -0
  10. package/docs/Chars/variables/digits.md +9 -0
  11. package/docs/Chars/variables/hex.md +9 -0
  12. package/docs/Chars/variables/hexDigits.md +9 -0
  13. package/docs/Chars/variables/hexDigitsUpper.md +9 -0
  14. package/docs/Chars/variables/letters.md +9 -0
  15. package/docs/Chars/variables/lowerCase.md +9 -0
  16. package/docs/Chars/variables/printable.md +9 -0
  17. package/docs/Chars/variables/symbols.md +9 -0
  18. package/docs/Chars/variables/upperCase.md +9 -0
  19. package/docs/Chars/variables/whitespace.md +9 -0
  20. package/docs/Generator/README.md +153 -0
  21. package/docs/Generator/classes/PseudoRandomGenerator.clone.md +17 -0
  22. package/docs/Generator/classes/PseudoRandomGenerator.create.md +24 -0
  23. package/docs/Generator/classes/PseudoRandomGenerator.createChild.md +24 -0
  24. package/docs/Generator/classes/PseudoRandomGenerator.ensureRng.md +25 -0
  25. package/docs/Generator/classes/PseudoRandomGenerator.getGlobalRng.md +17 -0
  26. package/docs/Generator/classes/PseudoRandomGenerator.md +258 -0
  27. package/docs/Generator/classes/PseudoRandomGenerator.nextBoolean.md +24 -0
  28. package/docs/Generator/classes/PseudoRandomGenerator.nextFloat.md +17 -0
  29. package/docs/Generator/classes/PseudoRandomGenerator.nextInRange.md +25 -0
  30. package/docs/Generator/classes/PseudoRandomGenerator.nextInt.md +24 -0
  31. package/docs/Generator/classes/PseudoRandomGenerator.nextString.md +25 -0
  32. package/docs/Generator/classes/PseudoRandomGenerator.pickNext.md +24 -0
  33. package/docs/Generator/classes/PseudoRandomGenerator.pickRandom.md +24 -0
  34. package/docs/Generator/classes/PseudoRandomGenerator.pickSequence.md +24 -0
  35. package/docs/Generator/classes/PseudoRandomGenerator.pickSequential.md +24 -0
  36. package/docs/Generator/classes/PseudoRandomGenerator.rng.md +11 -0
  37. package/docs/Generator/classes/PseudoRandomGenerator.setGlobalRng.md +24 -0
  38. package/docs/Generator/classes/SeededRandomSource.clone.md +17 -0
  39. package/docs/Generator/classes/SeededRandomSource.counter.md +11 -0
  40. package/docs/Generator/classes/SeededRandomSource.create.md +24 -0
  41. package/docs/Generator/classes/SeededRandomSource.createChild.md +24 -0
  42. package/docs/Generator/classes/SeededRandomSource.hashSeed.md +24 -0
  43. package/docs/Generator/classes/SeededRandomSource.hashStateAndLabel.md +25 -0
  44. package/docs/Generator/classes/SeededRandomSource.lineage.md +9 -0
  45. package/docs/Generator/classes/SeededRandomSource.md +187 -0
  46. package/docs/Generator/classes/SeededRandomSource.mulberryStep.md +24 -0
  47. package/docs/Generator/classes/SeededRandomSource.next.md +17 -0
  48. package/docs/Generator/classes/SeededRandomSource.seed.md +9 -0
  49. package/docs/Generator/interfaces/INextResult.md +61 -0
  50. package/docs/Generator/interfaces/INextResult.nextState.md +9 -0
  51. package/docs/Generator/interfaces/INextResult.value.md +9 -0
  52. package/docs/Generator/interfaces/IPseudoRandomGeneratorCreateParams.global.md +9 -0
  53. package/docs/Generator/interfaces/IPseudoRandomGeneratorCreateParams.md +78 -0
  54. package/docs/Generator/interfaces/IPseudoRandomGeneratorCreateParams.seed.md +9 -0
  55. package/docs/Generator/interfaces/IPseudoRandomGeneratorCreateParams.step.md +9 -0
  56. package/docs/Generator/interfaces/IRandomSequencePickParams.candidates.md +9 -0
  57. package/docs/Generator/interfaces/IRandomSequencePickParams.count.md +9 -0
  58. package/docs/Generator/interfaces/IRandomSequencePickParams.how.md +9 -0
  59. package/docs/Generator/interfaces/IRandomSequencePickParams.md +79 -0
  60. package/docs/Generator/interfaces/ISeedPair.md +61 -0
  61. package/docs/Generator/interfaces/ISeedPair.seed.md +9 -0
  62. package/docs/Generator/interfaces/ISeedPair.state.md +9 -0
  63. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.counter.md +9 -0
  64. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.lineage.md +9 -0
  65. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.md +112 -0
  66. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.seed.md +9 -0
  67. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.state.md +9 -0
  68. package/docs/Generator/interfaces/ISeededRandomSourceConstructorParams.step.md +9 -0
  69. package/docs/Generator/interfaces/ISeededRandomSourceCreateParams.md +61 -0
  70. package/docs/Generator/interfaces/ISeededRandomSourceCreateParams.seed.md +9 -0
  71. package/docs/Generator/interfaces/ISeededRandomSourceCreateParams.step.md +9 -0
  72. package/docs/Generator/interfaces/ISequentialPickParams.candidates.md +9 -0
  73. package/docs/Generator/interfaces/ISequentialPickParams.count.md +9 -0
  74. package/docs/Generator/interfaces/ISequentialPickParams.how.md +9 -0
  75. package/docs/Generator/interfaces/ISequentialPickParams.md +79 -0
  76. package/docs/Generator/type-aliases/GeneratorGlobalThis.md +11 -0
  77. package/docs/Generator/type-aliases/RandomStepFunction.md +11 -0
  78. package/docs/Generator/type-aliases/SequencePickParams.md +11 -0
  79. package/docs/GeneratorData/Chars/README.md +152 -0
  80. package/docs/GeneratorData/Chars/variables/all.md +9 -0
  81. package/docs/GeneratorData/Chars/variables/alphanumeric.md +9 -0
  82. package/docs/GeneratorData/Chars/variables/base64.md +9 -0
  83. package/docs/GeneratorData/Chars/variables/base64Url.md +9 -0
  84. package/docs/GeneratorData/Chars/variables/base64UrlNoPadding.md +9 -0
  85. package/docs/GeneratorData/Chars/variables/digits.md +9 -0
  86. package/docs/GeneratorData/Chars/variables/hex.md +9 -0
  87. package/docs/GeneratorData/Chars/variables/hexDigits.md +9 -0
  88. package/docs/GeneratorData/Chars/variables/hexDigitsUpper.md +9 -0
  89. package/docs/GeneratorData/Chars/variables/letters.md +9 -0
  90. package/docs/GeneratorData/Chars/variables/lowerCase.md +9 -0
  91. package/docs/GeneratorData/Chars/variables/printable.md +9 -0
  92. package/docs/GeneratorData/Chars/variables/symbols.md +9 -0
  93. package/docs/GeneratorData/Chars/variables/upperCase.md +9 -0
  94. package/docs/GeneratorData/Chars/variables/whitespace.md +9 -0
  95. package/docs/GeneratorData/README.md +35 -0
  96. package/docs/GeneratorData/Words/README.md +125 -0
  97. package/docs/GeneratorData/Words/variables/Adjectives.md +7 -0
  98. package/docs/GeneratorData/Words/variables/Animals.md +7 -0
  99. package/docs/GeneratorData/Words/variables/Cities.md +7 -0
  100. package/docs/GeneratorData/Words/variables/Colors.md +7 -0
  101. package/docs/GeneratorData/Words/variables/Countries.md +7 -0
  102. package/docs/GeneratorData/Words/variables/Domains.md +7 -0
  103. package/docs/GeneratorData/Words/variables/FamilyNames.md +9 -0
  104. package/docs/GeneratorData/Words/variables/FirstNames.md +9 -0
  105. package/docs/GeneratorData/Words/variables/FirstNamesFemale.md +9 -0
  106. package/docs/GeneratorData/Words/variables/FirstNamesMale.md +9 -0
  107. package/docs/GeneratorData/Words/variables/Gerunds.md +7 -0
  108. package/docs/GeneratorData/Words/variables/jobs.md +7 -0
  109. package/docs/GeneratorData/variables/Adjectives.md +7 -0
  110. package/docs/GeneratorData/variables/Animals.md +7 -0
  111. package/docs/GeneratorData/variables/Cities.md +7 -0
  112. package/docs/GeneratorData/variables/Colors.md +7 -0
  113. package/docs/GeneratorData/variables/Countries.md +7 -0
  114. package/docs/GeneratorData/variables/Domains.md +7 -0
  115. package/docs/GeneratorData/variables/FamilyNames.md +9 -0
  116. package/docs/GeneratorData/variables/FirstNames.md +9 -0
  117. package/docs/GeneratorData/variables/FirstNamesFemale.md +9 -0
  118. package/docs/GeneratorData/variables/FirstNamesMale.md +9 -0
  119. package/docs/GeneratorData/variables/Gerunds.md +7 -0
  120. package/docs/GeneratorData/variables/all.md +9 -0
  121. package/docs/GeneratorData/variables/alphanumeric.md +9 -0
  122. package/docs/GeneratorData/variables/base64.md +9 -0
  123. package/docs/GeneratorData/variables/base64Url.md +9 -0
  124. package/docs/GeneratorData/variables/base64UrlNoPadding.md +9 -0
  125. package/docs/GeneratorData/variables/digits.md +9 -0
  126. package/docs/GeneratorData/variables/hex.md +9 -0
  127. package/docs/GeneratorData/variables/hexDigits.md +9 -0
  128. package/docs/GeneratorData/variables/hexDigitsUpper.md +9 -0
  129. package/docs/GeneratorData/variables/jobs.md +7 -0
  130. package/docs/GeneratorData/variables/letters.md +9 -0
  131. package/docs/GeneratorData/variables/lowerCase.md +9 -0
  132. package/docs/GeneratorData/variables/printable.md +9 -0
  133. package/docs/GeneratorData/variables/symbols.md +9 -0
  134. package/docs/GeneratorData/variables/upperCase.md +9 -0
  135. package/docs/GeneratorData/variables/whitespace.md +9 -0
  136. package/docs/README.md +35 -0
  137. package/docs/Words/README.md +125 -0
  138. package/docs/Words/variables/Adjectives.md +7 -0
  139. package/docs/Words/variables/Animals.md +7 -0
  140. package/docs/Words/variables/Cities.md +7 -0
  141. package/docs/Words/variables/Colors.md +7 -0
  142. package/docs/Words/variables/Countries.md +7 -0
  143. package/docs/Words/variables/Domains.md +7 -0
  144. package/docs/Words/variables/FamilyNames.md +9 -0
  145. package/docs/Words/variables/FirstNames.md +9 -0
  146. package/docs/Words/variables/FirstNamesFemale.md +9 -0
  147. package/docs/Words/variables/FirstNamesMale.md +9 -0
  148. package/docs/Words/variables/Gerunds.md +7 -0
  149. package/docs/Words/variables/jobs.md +7 -0
  150. package/docs/classes/PseudoRandomGenerator.clone.md +17 -0
  151. package/docs/classes/PseudoRandomGenerator.create.md +24 -0
  152. package/docs/classes/PseudoRandomGenerator.createChild.md +24 -0
  153. package/docs/classes/PseudoRandomGenerator.ensureRng.md +25 -0
  154. package/docs/classes/PseudoRandomGenerator.getGlobalRng.md +17 -0
  155. package/docs/classes/PseudoRandomGenerator.md +258 -0
  156. package/docs/classes/PseudoRandomGenerator.nextBoolean.md +24 -0
  157. package/docs/classes/PseudoRandomGenerator.nextFloat.md +17 -0
  158. package/docs/classes/PseudoRandomGenerator.nextInRange.md +25 -0
  159. package/docs/classes/PseudoRandomGenerator.nextInt.md +24 -0
  160. package/docs/classes/PseudoRandomGenerator.nextString.md +25 -0
  161. package/docs/classes/PseudoRandomGenerator.pickNext.md +24 -0
  162. package/docs/classes/PseudoRandomGenerator.pickRandom.md +24 -0
  163. package/docs/classes/PseudoRandomGenerator.pickSequence.md +24 -0
  164. package/docs/classes/PseudoRandomGenerator.pickSequential.md +24 -0
  165. package/docs/classes/PseudoRandomGenerator.rng.md +11 -0
  166. package/docs/classes/PseudoRandomGenerator.setGlobalRng.md +24 -0
  167. package/docs/classes/SeededRandomSource.clone.md +17 -0
  168. package/docs/classes/SeededRandomSource.counter.md +11 -0
  169. package/docs/classes/SeededRandomSource.create.md +24 -0
  170. package/docs/classes/SeededRandomSource.createChild.md +24 -0
  171. package/docs/classes/SeededRandomSource.hashSeed.md +24 -0
  172. package/docs/classes/SeededRandomSource.hashStateAndLabel.md +25 -0
  173. package/docs/classes/SeededRandomSource.lineage.md +9 -0
  174. package/docs/classes/SeededRandomSource.md +187 -0
  175. package/docs/classes/SeededRandomSource.mulberryStep.md +24 -0
  176. package/docs/classes/SeededRandomSource.next.md +17 -0
  177. package/docs/classes/SeededRandomSource.seed.md +9 -0
  178. package/docs/interfaces/INextResult.md +61 -0
  179. package/docs/interfaces/INextResult.nextState.md +9 -0
  180. package/docs/interfaces/INextResult.value.md +9 -0
  181. package/docs/interfaces/IPseudoRandomGeneratorCreateParams.global.md +9 -0
  182. package/docs/interfaces/IPseudoRandomGeneratorCreateParams.md +78 -0
  183. package/docs/interfaces/IPseudoRandomGeneratorCreateParams.seed.md +9 -0
  184. package/docs/interfaces/IPseudoRandomGeneratorCreateParams.step.md +9 -0
  185. package/docs/interfaces/IRandomSequencePickParams.candidates.md +9 -0
  186. package/docs/interfaces/IRandomSequencePickParams.count.md +9 -0
  187. package/docs/interfaces/IRandomSequencePickParams.how.md +9 -0
  188. package/docs/interfaces/IRandomSequencePickParams.md +79 -0
  189. package/docs/interfaces/ISeedPair.md +61 -0
  190. package/docs/interfaces/ISeedPair.seed.md +9 -0
  191. package/docs/interfaces/ISeedPair.state.md +9 -0
  192. package/docs/interfaces/ISeededRandomSourceConstructorParams.counter.md +9 -0
  193. package/docs/interfaces/ISeededRandomSourceConstructorParams.lineage.md +9 -0
  194. package/docs/interfaces/ISeededRandomSourceConstructorParams.md +112 -0
  195. package/docs/interfaces/ISeededRandomSourceConstructorParams.seed.md +9 -0
  196. package/docs/interfaces/ISeededRandomSourceConstructorParams.state.md +9 -0
  197. package/docs/interfaces/ISeededRandomSourceConstructorParams.step.md +9 -0
  198. package/docs/interfaces/ISeededRandomSourceCreateParams.md +61 -0
  199. package/docs/interfaces/ISeededRandomSourceCreateParams.seed.md +9 -0
  200. package/docs/interfaces/ISeededRandomSourceCreateParams.step.md +9 -0
  201. package/docs/interfaces/ISequentialPickParams.candidates.md +9 -0
  202. package/docs/interfaces/ISequentialPickParams.count.md +9 -0
  203. package/docs/interfaces/ISequentialPickParams.how.md +9 -0
  204. package/docs/interfaces/ISequentialPickParams.md +79 -0
  205. package/docs/type-aliases/GeneratorGlobalThis.md +11 -0
  206. package/docs/type-aliases/RandomStepFunction.md +11 -0
  207. package/docs/type-aliases/SequencePickParams.md +11 -0
  208. package/docs/variables/Adjectives.md +7 -0
  209. package/docs/variables/Animals.md +7 -0
  210. package/docs/variables/Cities.md +7 -0
  211. package/docs/variables/Colors.md +7 -0
  212. package/docs/variables/Countries.md +7 -0
  213. package/docs/variables/Domains.md +7 -0
  214. package/docs/variables/FamilyNames.md +9 -0
  215. package/docs/variables/FirstNames.md +9 -0
  216. package/docs/variables/FirstNamesFemale.md +9 -0
  217. package/docs/variables/FirstNamesMale.md +9 -0
  218. package/docs/variables/Gerunds.md +7 -0
  219. package/docs/variables/all.md +9 -0
  220. package/docs/variables/alphanumeric.md +9 -0
  221. package/docs/variables/base64.md +9 -0
  222. package/docs/variables/base64Url.md +9 -0
  223. package/docs/variables/base64UrlNoPadding.md +9 -0
  224. package/docs/variables/digits.md +9 -0
  225. package/docs/variables/hex.md +9 -0
  226. package/docs/variables/hexDigits.md +9 -0
  227. package/docs/variables/hexDigitsUpper.md +9 -0
  228. package/docs/variables/jobs.md +7 -0
  229. package/docs/variables/letters.md +9 -0
  230. package/docs/variables/lowerCase.md +9 -0
  231. package/docs/variables/printable.md +9 -0
  232. package/docs/variables/symbols.md +9 -0
  233. package/docs/variables/upperCase.md +9 -0
  234. package/docs/variables/whitespace.md +9 -0
  235. package/package.json +49 -0
  236. package/src/generator/generators.ts +273 -0
  237. package/src/generator/index.ts +22 -0
  238. package/src/generator/randomSource.ts +224 -0
  239. package/src/generator-data/charClasses.ts +95 -0
  240. package/src/generator-data/index.ts +22 -0
  241. package/src/generator-data/words/adjectives.ts +247 -0
  242. package/src/generator-data/words/animals.ts +75 -0
  243. package/src/generator-data/words/cities.ts +229 -0
  244. package/src/generator-data/words/colors.ts +56 -0
  245. package/src/generator-data/words/countries.ts +217 -0
  246. package/src/generator-data/words/domains.ts +47 -0
  247. package/src/generator-data/words/gerunds.ts +126 -0
  248. package/src/generator-data/words/index.ts +29 -0
  249. package/src/generator-data/words/jobs.ts +175 -0
  250. package/src/generator-data/words/names.ts +717 -0
  251. package/src/index.ts +7 -0
  252. package/src/test/unit/generators.test.ts +697 -0
  253. package/src/test/unit/randomSource.test.ts +526 -0
  254. package/tsconfig.json +7 -0
@@ -0,0 +1,224 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+
21
+ import { captureResult, Result } from '@fgv/ts-utils';
22
+
23
+ /**
24
+ * Represents a seed as both a string and a number.
25
+ * @public
26
+ */
27
+ export interface ISeedPair {
28
+ seed: string;
29
+ state: number;
30
+ }
31
+
32
+ /**
33
+ * Result of an internal next() operation.
34
+ * @public
35
+ */
36
+ export interface INextResult {
37
+ value: number;
38
+ nextState: number;
39
+ }
40
+
41
+ /**
42
+ * Function that steps a random number generator state and returns the next value.
43
+ * @public
44
+ */
45
+ export type RandomStepFunction = (state: number) => INextResult;
46
+
47
+ /**
48
+ * Constructor params for a {@link Generator.SeededRandomSource | SeededRandomSource}.
49
+ * @public
50
+ */
51
+ export interface ISeededRandomSourceConstructorParams {
52
+ state: number;
53
+ seed: string;
54
+ counter: number;
55
+ lineage: ReadonlyArray<string>;
56
+ step: RandomStepFunction;
57
+ }
58
+
59
+ /**
60
+ * Static create parameters for a {@link Generator.SeededRandomSource | SeededRandomSource}.
61
+ * @public
62
+ */
63
+ export interface ISeededRandomSourceCreateParams {
64
+ seed?: number | string;
65
+ step?: RandomStepFunction;
66
+ }
67
+
68
+ /**
69
+ * Seeded random number generator that can be cloned and used for deterministic generation.
70
+ * @public
71
+ */
72
+ export class SeededRandomSource {
73
+ private currentState: number;
74
+ public readonly seed: string;
75
+ public readonly lineage: ReadonlyArray<string>;
76
+ private _counter: number;
77
+ private _step: RandomStepFunction;
78
+
79
+ /**
80
+ * Gets the current counter value.
81
+ */
82
+ public get counter(): number {
83
+ return this._counter;
84
+ }
85
+
86
+ /**
87
+ * Creates a new seeded random source.
88
+ * @param seed - The seed value.
89
+ */
90
+ protected constructor(init: ISeededRandomSourceConstructorParams) {
91
+ this.currentState = init.state;
92
+ this.seed = init.seed;
93
+ this._counter = init.counter;
94
+ this._step = init.step;
95
+ this.lineage = init.lineage;
96
+ }
97
+
98
+ /**
99
+ * Creates a new seeded random source from an optional seed.
100
+ * @param seed - The optional seed value.
101
+ * @returns A new seeded random source.
102
+ */
103
+ public static create(seed?: number | string): Result<SeededRandomSource>;
104
+
105
+ /**
106
+ * Creates a new seeded random source from {@link Generator.ISeededRandomSourceCreateParams | ISeededRandomSourceCreateParams}.
107
+ * @param init - The initialization parameters.
108
+ * @returns A new seeded random source.
109
+ */
110
+ public static create(init: ISeededRandomSourceCreateParams): Result<SeededRandomSource>;
111
+
112
+ public static create(
113
+ seedOrInit?: number | string | ISeededRandomSourceCreateParams
114
+ ): Result<SeededRandomSource> {
115
+ const init = typeof seedOrInit === 'object' ? seedOrInit : { seed: seedOrInit };
116
+ const step = init?.step ?? SeededRandomSource.mulberryStep;
117
+ const { seed, state } = SeededRandomSource.hashSeed(init?.seed ?? Date.now());
118
+ return captureResult(
119
+ () =>
120
+ new SeededRandomSource({
121
+ state,
122
+ seed,
123
+ counter: 0,
124
+ lineage: [],
125
+ step
126
+ })
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Generates the next random number.
132
+ * @returns A random number between 0 and 1.
133
+ */
134
+ public next(): number {
135
+ this._counter += 1;
136
+ const { value, nextState } = this._step(this.currentState);
137
+ this.currentState = nextState;
138
+ return value;
139
+ }
140
+
141
+ /**
142
+ * Creates a clone of this random source.
143
+ * @returns A new seeded random source with the same state.
144
+ */
145
+ public clone(): SeededRandomSource {
146
+ return new SeededRandomSource({
147
+ state: this.currentState,
148
+ seed: this.seed,
149
+ counter: this._counter,
150
+ lineage: this.lineage,
151
+ step: this._step
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Creates a child random source with a label.
157
+ * @param label - The label for the child.
158
+ * @returns A new seeded random source with a hashed state and label.
159
+ */
160
+ public createChild(label: string): SeededRandomSource {
161
+ const { seed, state } = SeededRandomSource.hashStateAndLabel(this.currentState, label);
162
+ const lineage = [...this.lineage, `${this._counter}:${label}`];
163
+ return new SeededRandomSource({ state, seed, counter: 0, lineage, step: this._step });
164
+ }
165
+
166
+ /**
167
+ * Steps a mulberry32 random number generator state and returns the next value.
168
+ * @param currentState - The current state of the generator.
169
+ * @returns The next random number and the next state.
170
+ */
171
+ public static mulberryStep(currentState: number): INextResult {
172
+ const nextState = (currentState + 0x6d2b79f5) >>> 0;
173
+
174
+ let t = nextState;
175
+ t = Math.imul(t ^ (t >>> 15), t | 1);
176
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
177
+
178
+ const value = ((t ^ (t >>> 14)) >>> 0) / 4294967296;
179
+ return { value, nextState };
180
+ }
181
+
182
+ /**
183
+ * Hashes a seed value.
184
+ * @param seed - The seed value.
185
+ * @returns A hashed seed value.
186
+ */
187
+ public static hashSeed(seed: number | string): ISeedPair {
188
+ if (typeof seed === 'number') {
189
+ return { seed: seed.toString(), state: seed };
190
+ }
191
+ const parsedSeed = Number(seed);
192
+ if (!isNaN(parsedSeed) && isFinite(parsedSeed)) {
193
+ return { seed, state: parsedSeed };
194
+ }
195
+ return { seed, state: SeededRandomSource.hashString(seed) };
196
+ }
197
+
198
+ /**
199
+ * Hashes a state and label.
200
+ * @param state - The state value.
201
+ * @param label - The label value.
202
+ * @returns A hashed state and label value.
203
+ */
204
+ public static hashStateAndLabel(state: number, label: string): ISeedPair {
205
+ const seed = `${state >>> 0}:${label}`;
206
+ return { seed, state: SeededRandomSource.hashString(seed) };
207
+ }
208
+
209
+ /**
210
+ * Hashes a string value.
211
+ * @param value - The string value.
212
+ * @returns A hashed string value.
213
+ */
214
+ private static hashString(value: string): number {
215
+ let hash = 0x811c9dc5;
216
+
217
+ for (let index = 0; index < value.length; index++) {
218
+ hash ^= value.charCodeAt(index);
219
+ hash = Math.imul(hash, 0x01000193);
220
+ }
221
+
222
+ return hash >>> 0;
223
+ }
224
+ }
@@ -0,0 +1,95 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+
21
+ /**
22
+ * Lowercase letters
23
+ * @public
24
+ */
25
+ export const lowerCase: string = 'abcdefghijklmnopqrstuvwxyz';
26
+ /**
27
+ * Uppercase letters
28
+ * @public
29
+ */
30
+ export const upperCase: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
31
+ /**
32
+ * Digits
33
+ * @public
34
+ */
35
+ export const digits: string = '0123456789';
36
+ /**
37
+ * Letters
38
+ * @public
39
+ */
40
+ export const letters: string = lowerCase + upperCase;
41
+ /**
42
+ * Alphanumeric
43
+ * @public
44
+ */
45
+ export const alphanumeric: string = letters + digits;
46
+ /**
47
+ * Symbols
48
+ * @public
49
+ */
50
+ export const symbols: string = '!@#$%^&*()_+-=[]{}|;:,.<>?';
51
+ /**
52
+ * Whitespace
53
+ * @public
54
+ */
55
+ export const whitespace: string = ' \t\n\r';
56
+ /**
57
+ * Printable
58
+ * @public
59
+ */
60
+ export const printable: string = letters + digits + symbols + whitespace;
61
+ /**
62
+ * All
63
+ * @public
64
+ */
65
+ export const all: string = printable;
66
+ /**
67
+ * Hex digits
68
+ * @public
69
+ */
70
+ export const hexDigits: string = '0123456789abcdef';
71
+ /**
72
+ * Hex digits upper
73
+ * @public
74
+ */
75
+ export const hexDigitsUpper: string = '0123456789ABCDEF';
76
+ /**
77
+ * Hex
78
+ * @public
79
+ */
80
+ export const hex: string = hexDigits + hexDigitsUpper;
81
+ /**
82
+ * Base64
83
+ * @public
84
+ */
85
+ export const base64: string = letters + digits + '+/';
86
+ /**
87
+ * Base64 URL
88
+ * @public
89
+ */
90
+ export const base64Url: string = letters + digits + '-_';
91
+ /**
92
+ * Base64 URL no padding
93
+ * @public
94
+ */
95
+ export const base64UrlNoPadding: string = base64Url + '=';
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+
21
+ export * as Chars from './charClasses';
22
+ export * as Words from './words';
@@ -0,0 +1,247 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+
21
+ export const Adjectives: ReadonlyArray<string> = [
22
+ 'happy',
23
+ 'sad',
24
+ 'angry',
25
+ 'calm',
26
+ 'excited',
27
+ 'bored',
28
+ 'tired',
29
+ 'hungry',
30
+ 'thirsty',
31
+ 'sleepy',
32
+ 'awake',
33
+ 'alert',
34
+ 'anxious',
35
+ 'brave',
36
+ 'bright',
37
+ 'brilliant',
38
+ 'busy',
39
+ 'careful',
40
+ 'careless',
41
+ 'cautious',
42
+ 'cheerful',
43
+ 'clever',
44
+ 'clumsy',
45
+ 'confident',
46
+ 'confused',
47
+ 'content',
48
+ 'courageous',
49
+ 'cowardly',
50
+ 'creative',
51
+ 'cruel',
52
+ 'curious',
53
+ 'daring',
54
+ 'dark',
55
+ 'delightful',
56
+ 'determined',
57
+ 'diligent',
58
+ 'dizzy',
59
+ 'doubtful',
60
+ 'eager',
61
+ 'elegant',
62
+ 'embarrassed',
63
+ 'energetic',
64
+ 'enthusiastic',
65
+ 'envious',
66
+ 'evil',
67
+ 'faithful',
68
+ 'famous',
69
+ 'fancy',
70
+ 'fantastic',
71
+ 'fearful',
72
+ 'fearless',
73
+ 'fierce',
74
+ 'filthy',
75
+ 'foolish',
76
+ 'fortunate',
77
+ 'fragile',
78
+ 'frantic',
79
+ 'friendly',
80
+ 'frightened',
81
+ 'funny',
82
+ 'generous',
83
+ 'gentle',
84
+ 'gloomy',
85
+ 'glorious',
86
+ 'graceful',
87
+ 'grateful',
88
+ 'greedy',
89
+ 'grumpy',
90
+ 'guilty',
91
+ 'handsome',
92
+ 'harsh',
93
+ 'hasty',
94
+ 'healthy',
95
+ 'helpful',
96
+ 'helpless',
97
+ 'hesitant',
98
+ 'hilarious',
99
+ 'honest',
100
+ 'hopeful',
101
+ 'hopeless',
102
+ 'horrible',
103
+ 'hostile',
104
+ 'humble',
105
+ 'humorous',
106
+ 'ignorant',
107
+ 'imaginative',
108
+ 'impatient',
109
+ 'important',
110
+ 'impossible',
111
+ 'impressive',
112
+ 'incredible',
113
+ 'independent',
114
+ 'innocent',
115
+ 'intelligent',
116
+ 'interesting',
117
+ 'jealous',
118
+ 'joyful',
119
+ 'joyous',
120
+ 'kind',
121
+ 'lazy',
122
+ 'lively',
123
+ 'lonely',
124
+ 'lovely',
125
+ 'loyal',
126
+ 'lucky',
127
+ 'magnificent',
128
+ 'marvelous',
129
+ 'mature',
130
+ 'mean',
131
+ 'melancholy',
132
+ 'merry',
133
+ 'mighty',
134
+ 'miserable',
135
+ 'modest',
136
+ 'mysterious',
137
+ 'nasty',
138
+ 'naughty',
139
+ 'nervous',
140
+ 'nice',
141
+ 'noble',
142
+ 'noisy',
143
+ 'obedient',
144
+ 'obnoxious',
145
+ 'odd',
146
+ 'optimistic',
147
+ 'outrageous',
148
+ 'peaceful',
149
+ 'peculiar',
150
+ 'perfect',
151
+ 'persistent',
152
+ 'pessimistic',
153
+ 'pleasant',
154
+ 'polite',
155
+ 'poor',
156
+ 'popular',
157
+ 'positive',
158
+ 'powerful',
159
+ 'precious',
160
+ 'proud',
161
+ 'puzzled',
162
+ 'quiet',
163
+ 'rapid',
164
+ 'rare',
165
+ 'reckless',
166
+ 'relaxed',
167
+ 'reliable',
168
+ 'relieved',
169
+ 'reluctant',
170
+ 'remarkable',
171
+ 'reserved',
172
+ 'respectful',
173
+ 'responsible',
174
+ 'restless',
175
+ 'rich',
176
+ 'ridiculous',
177
+ 'romantic',
178
+ 'rough',
179
+ 'rude',
180
+ 'ruthless',
181
+ 'satisfied',
182
+ 'scared',
183
+ 'selfish',
184
+ 'sensible',
185
+ 'sensitive',
186
+ 'serious',
187
+ 'sharp',
188
+ 'shy',
189
+ 'silly',
190
+ 'sincere',
191
+ 'skeptical',
192
+ 'skillful',
193
+ 'sleek',
194
+ 'sly',
195
+ 'smart',
196
+ 'sneaky',
197
+ 'sociable',
198
+ 'sorrowful',
199
+ 'splendid',
200
+ 'spontaneous',
201
+ 'stern',
202
+ 'strange',
203
+ 'strong',
204
+ 'stubborn',
205
+ 'stunning',
206
+ 'stupid',
207
+ 'successful',
208
+ 'suspicious',
209
+ 'sweet',
210
+ 'talented',
211
+ 'tense',
212
+ 'terrible',
213
+ 'thankful',
214
+ 'thoughtful',
215
+ 'timid',
216
+ 'tough',
217
+ 'tragic',
218
+ 'tremendous',
219
+ 'troubled',
220
+ 'trustworthy',
221
+ 'ugly',
222
+ 'unique',
223
+ 'unlucky',
224
+ 'unusual',
225
+ 'upset',
226
+ 'useful',
227
+ 'useless',
228
+ 'vain',
229
+ 'victorious',
230
+ 'vigorous',
231
+ 'violent',
232
+ 'vivid',
233
+ 'warm',
234
+ 'weak',
235
+ 'wealthy',
236
+ 'weary',
237
+ 'wicked',
238
+ 'wild',
239
+ 'wise',
240
+ 'witty',
241
+ 'wonderful',
242
+ 'worried',
243
+ 'worthy',
244
+ 'wretched',
245
+ 'youthful',
246
+ 'zealous'
247
+ ];
@@ -0,0 +1,75 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+
21
+ export const Animals: ReadonlyArray<string> = [
22
+ 'cat',
23
+ 'dog',
24
+ 'bird',
25
+ 'fish',
26
+ 'rabbit',
27
+ 'hamster',
28
+ 'panda',
29
+ 'cow',
30
+ 'horse',
31
+ 'sheep',
32
+ 'goat',
33
+ 'pig',
34
+ 'chicken',
35
+ 'duck',
36
+ 'turkey',
37
+ 'goose',
38
+ 'rabbit',
39
+ 'fox',
40
+ 'wolf',
41
+ 'bear',
42
+ 'capybara',
43
+ 'panda',
44
+ 'koala',
45
+ 'red panda',
46
+ 'pangolin',
47
+ 'anteater',
48
+ 'armadillo',
49
+ 'porcupine',
50
+ 'hippopotamus',
51
+ 'rhinoceros',
52
+ 'elephant',
53
+ 'giraffe',
54
+ 'zebra',
55
+ 'monkey',
56
+ 'gorilla',
57
+ 'chimpanzee',
58
+ 'orangutan',
59
+ 'turtle',
60
+ 'snake',
61
+ 'lizard',
62
+ 'frog',
63
+ 'toad',
64
+ 'salamander',
65
+ 'newt',
66
+ 'axolotl',
67
+ 'gecko',
68
+ 'chameleon',
69
+ 'iguana',
70
+ 'snake',
71
+ 'python',
72
+ 'cobra',
73
+ 'viper',
74
+ 'rattlesnake'
75
+ ];