@elaraai/east-web-std 1.0.85

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 (102) hide show
  1. package/CLA.md +26 -0
  2. package/CONTRIBUTING.md +28 -0
  3. package/LICENSE.md +31 -0
  4. package/README.md +191 -0
  5. package/THIRD_PARTY_NOTICES.md +123 -0
  6. package/dist/src/compliance.spec.d.ts +6 -0
  7. package/dist/src/compliance.spec.d.ts.map +1 -0
  8. package/dist/src/compliance.spec.js +89 -0
  9. package/dist/src/compliance.spec.js.map +1 -0
  10. package/dist/src/console.d.ts +237 -0
  11. package/dist/src/console.d.ts.map +1 -0
  12. package/dist/src/console.js +260 -0
  13. package/dist/src/console.js.map +1 -0
  14. package/dist/src/crypto.d.ts +224 -0
  15. package/dist/src/crypto.d.ts.map +1 -0
  16. package/dist/src/crypto.js +295 -0
  17. package/dist/src/crypto.js.map +1 -0
  18. package/dist/src/fetch.d.ts +383 -0
  19. package/dist/src/fetch.d.ts.map +1 -0
  20. package/dist/src/fetch.js +412 -0
  21. package/dist/src/fetch.js.map +1 -0
  22. package/dist/src/index.d.ts +106 -0
  23. package/dist/src/index.d.ts.map +1 -0
  24. package/dist/src/index.js +93 -0
  25. package/dist/src/index.js.map +1 -0
  26. package/dist/src/path.d.ts +243 -0
  27. package/dist/src/path.d.ts.map +1 -0
  28. package/dist/src/path.js +562 -0
  29. package/dist/src/path.js.map +1 -0
  30. package/dist/src/random/crypto-rng.d.ts +38 -0
  31. package/dist/src/random/crypto-rng.d.ts.map +1 -0
  32. package/dist/src/random/crypto-rng.js +55 -0
  33. package/dist/src/random/crypto-rng.js.map +1 -0
  34. package/dist/src/random/distributions/bates.d.ts +17 -0
  35. package/dist/src/random/distributions/bates.d.ts.map +1 -0
  36. package/dist/src/random/distributions/bates.js +15 -0
  37. package/dist/src/random/distributions/bates.js.map +1 -0
  38. package/dist/src/random/distributions/bernoulli.d.ts +17 -0
  39. package/dist/src/random/distributions/bernoulli.d.ts.map +1 -0
  40. package/dist/src/random/distributions/bernoulli.js +13 -0
  41. package/dist/src/random/distributions/bernoulli.js.map +1 -0
  42. package/dist/src/random/distributions/binomial.d.ts +17 -0
  43. package/dist/src/random/distributions/binomial.d.ts.map +1 -0
  44. package/dist/src/random/distributions/binomial.js +24 -0
  45. package/dist/src/random/distributions/binomial.js.map +1 -0
  46. package/dist/src/random/distributions/exponential.d.ts +17 -0
  47. package/dist/src/random/distributions/exponential.d.ts.map +1 -0
  48. package/dist/src/random/distributions/exponential.js +13 -0
  49. package/dist/src/random/distributions/exponential.js.map +1 -0
  50. package/dist/src/random/distributions/geometric.d.ts +17 -0
  51. package/dist/src/random/distributions/geometric.d.ts.map +1 -0
  52. package/dist/src/random/distributions/geometric.js +14 -0
  53. package/dist/src/random/distributions/geometric.js.map +1 -0
  54. package/dist/src/random/distributions/irwin-hall.d.ts +17 -0
  55. package/dist/src/random/distributions/irwin-hall.d.ts.map +1 -0
  56. package/dist/src/random/distributions/irwin-hall.js +18 -0
  57. package/dist/src/random/distributions/irwin-hall.js.map +1 -0
  58. package/dist/src/random/distributions/log-normal.d.ts +17 -0
  59. package/dist/src/random/distributions/log-normal.d.ts.map +1 -0
  60. package/dist/src/random/distributions/log-normal.js +12 -0
  61. package/dist/src/random/distributions/log-normal.js.map +1 -0
  62. package/dist/src/random/distributions/normal.d.ts +18 -0
  63. package/dist/src/random/distributions/normal.d.ts.map +1 -0
  64. package/dist/src/random/distributions/normal.js +16 -0
  65. package/dist/src/random/distributions/normal.js.map +1 -0
  66. package/dist/src/random/distributions/pareto.d.ts +17 -0
  67. package/dist/src/random/distributions/pareto.d.ts.map +1 -0
  68. package/dist/src/random/distributions/pareto.js +14 -0
  69. package/dist/src/random/distributions/pareto.js.map +1 -0
  70. package/dist/src/random/distributions/poisson.d.ts +17 -0
  71. package/dist/src/random/distributions/poisson.d.ts.map +1 -0
  72. package/dist/src/random/distributions/poisson.js +81 -0
  73. package/dist/src/random/distributions/poisson.js.map +1 -0
  74. package/dist/src/random/distributions/uniform-int.d.ts +17 -0
  75. package/dist/src/random/distributions/uniform-int.d.ts.map +1 -0
  76. package/dist/src/random/distributions/uniform-int.js +16 -0
  77. package/dist/src/random/distributions/uniform-int.js.map +1 -0
  78. package/dist/src/random/distributions/uniform.d.ts +17 -0
  79. package/dist/src/random/distributions/uniform.d.ts.map +1 -0
  80. package/dist/src/random/distributions/uniform.js +10 -0
  81. package/dist/src/random/distributions/uniform.js.map +1 -0
  82. package/dist/src/random/rng.d.ts +21 -0
  83. package/dist/src/random/rng.d.ts.map +1 -0
  84. package/dist/src/random/rng.js +7 -0
  85. package/dist/src/random/rng.js.map +1 -0
  86. package/dist/src/random/xorshift128.d.ts +42 -0
  87. package/dist/src/random/xorshift128.d.ts.map +1 -0
  88. package/dist/src/random/xorshift128.js +119 -0
  89. package/dist/src/random/xorshift128.js.map +1 -0
  90. package/dist/src/random.d.ts +822 -0
  91. package/dist/src/random.d.ts.map +1 -0
  92. package/dist/src/random.js +992 -0
  93. package/dist/src/random.js.map +1 -0
  94. package/dist/src/test.d.ts +86 -0
  95. package/dist/src/test.d.ts.map +1 -0
  96. package/dist/src/test.js +160 -0
  97. package/dist/src/test.js.map +1 -0
  98. package/dist/src/time.d.ts +201 -0
  99. package/dist/src/time.d.ts.map +1 -0
  100. package/dist/src/time.js +300 -0
  101. package/dist/src/time.js.map +1 -0
  102. package/package.json +64 -0
@@ -0,0 +1,822 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Random number generation for East programs in a browser.
7
+ *
8
+ * Ported from east-node-std's src/random.ts
9
+ * (libs/east-node/packages/east-node-std/src/random.ts): the same platform
10
+ * functions, types and algorithms, so a seed gives the stream east-node-std
11
+ * gives, bit for bit (test/random.spec.ts checks it). One thing differs:
12
+ * east-node-std keeps one generator for its process, and a browser keeps the
13
+ * generator in the implementation, so each {@link createRandomImpl} starts
14
+ * unseeded, as a new east-node process does.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { FloatType, IntegerType, NullType } from "@elaraai/east";
19
+ import type { PlatformFunction } from "@elaraai/east/internal";
20
+ import XorShift128RNG from "./random/xorshift128.js";
21
+ /**
22
+ * Generates a uniform random float in the range [0.0, 1.0).
23
+ *
24
+ * Returns a uniformly distributed random floating-point number greater than or equal to 0.0
25
+ * and strictly less than 1.0. Uses cryptographically secure random number generation by default.
26
+ *
27
+ * This is a platform function for the East language, enabling secure random number generation
28
+ * in East programs running in a browser.
29
+ *
30
+ * @returns A random float in [0.0, 1.0)
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const generateRandom = East.function([], FloatType, $ => {
35
+ * return Random.uniform();
36
+ * });
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * - Uses the web-standard crypto.getRandomValues for cryptographic security
41
+ * - Uniform distribution across the range
42
+ * - Never returns exactly 1.0
43
+ */
44
+ export declare const random_uniform: import("@elaraai/east").PlatformDefinition<[], FloatType>;
45
+ /**
46
+ * Generates a random float from a standard normal distribution (mean=0, standard deviation=1).
47
+ *
48
+ * Returns a random floating-point number drawn from a normal (Gaussian) distribution
49
+ * with mean 0.0 and standard deviation 1.0. Uses the Marsaglia polar method for
50
+ * high-quality normal distribution sampling.
51
+ *
52
+ * This is a platform function for the East language, enabling normal distribution sampling
53
+ * in East programs running in a browser.
54
+ *
55
+ * @returns A random float from N(0, 1)
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const generateNormal = East.function([], FloatType, $ => {
60
+ * const z = $.let(Random.normal());
61
+ * // Scale and shift: z * stddev + mean
62
+ * return z.multiply(2.5).add(10.0); // N(10, 2.5)
63
+ * });
64
+ * ```
65
+ *
66
+ * @remarks
67
+ * - Uses Marsaglia polar method for high-quality normal distribution
68
+ * - Mean: 0.0, Standard deviation: 1.0
69
+ * - Can return any real number (unbounded range)
70
+ * - Use `.multiply(stddev).add(mean)` to scale/shift distribution
71
+ */
72
+ export declare const random_normal: import("@elaraai/east").PlatformDefinition<[], FloatType>;
73
+ /**
74
+ * Generates a random integer in the range [min, max] (both endpoints inclusive).
75
+ *
76
+ * Returns a uniformly distributed random integer between min and max (both inclusive).
77
+ * Uses cryptographically secure random number generation. The range must be valid (min ≤ max).
78
+ *
79
+ * This is a platform function for the East language, enabling random integer generation
80
+ * in East programs running in a browser.
81
+ *
82
+ * @param min - The minimum value (inclusive)
83
+ * @param max - The maximum value (inclusive)
84
+ * @returns A random integer in [min, max]
85
+ *
86
+ * @throws {EastError} When min > max
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const rollDice = East.function([], IntegerType, $ => {
91
+ * return Random.range(1n, 6n); // 1-6 inclusive
92
+ * });
93
+ * ```
94
+ *
95
+ * @remarks
96
+ * - Both min and max are inclusive
97
+ * - Uniform distribution across the range
98
+ * - Uses floor method to avoid modulo bias
99
+ */
100
+ export declare const random_range: import("@elaraai/east").PlatformDefinition<[IntegerType, IntegerType], IntegerType>;
101
+ /**
102
+ * Generates a random float from an exponential distribution.
103
+ *
104
+ * Returns a random floating-point number drawn from an exponential distribution
105
+ * with rate parameter lambda (λ). The mean of the distribution is 1/λ.
106
+ * Commonly used for modeling time between events in a Poisson process.
107
+ *
108
+ * This is a platform function for the East language, enabling exponential distribution sampling
109
+ * in East programs running in a browser.
110
+ *
111
+ * @param lambda - Rate parameter (λ > 0), default 1.0. Mean = 1/λ
112
+ * @returns A random float from Exp(λ)
113
+ *
114
+ * @throws {EastError} When lambda ≤ 0
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const waitTime = East.function([], FloatType, $ => {
119
+ * // Average wait time of 5 minutes (lambda = 0.2)
120
+ * return Random.exponential(0.2);
121
+ * });
122
+ * ```
123
+ *
124
+ * @remarks
125
+ * - Uses inverse transform sampling: -ln(U) / λ
126
+ * - Always returns positive values
127
+ * - Mean = 1/λ, Variance = 1/λ²
128
+ * - Memoryless property: P(X > s + t | X > s) = P(X > t)
129
+ */
130
+ export declare const random_exponential: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
131
+ /**
132
+ * Generates a random float from a Weibull distribution.
133
+ *
134
+ * Returns a random floating-point number drawn from a Weibull distribution
135
+ * with shape parameter k. Uses exponential distribution transformation.
136
+ * Commonly used for modeling failure rates and lifetime distributions.
137
+ *
138
+ * This is a platform function for the East language, enabling Weibull distribution sampling
139
+ * in East programs running in a browser.
140
+ *
141
+ * @param shape - Shape parameter (k > 0). k=1 gives exponential, k>1 increases failure rate
142
+ * @returns A random float from Weibull(k, 1)
143
+ *
144
+ * @throws {EastError} When shape ≤ 0
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const lifetime = East.function([], FloatType, $ => {
149
+ * // Shape=2 models wear-out failures
150
+ * return Random.weibull(2.0);
151
+ * });
152
+ * ```
153
+ *
154
+ * @remarks
155
+ * - Uses transformation: exponential() ^ (1/shape)
156
+ * - Shape < 1: decreasing failure rate
157
+ * - Shape = 1: constant failure rate (exponential)
158
+ * - Shape > 1: increasing failure rate
159
+ */
160
+ export declare const random_weibull: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
161
+ /**
162
+ * Generates a binary random outcome (0 or 1).
163
+ *
164
+ * Returns 0 or 1 based on success probability p. This models a single
165
+ * Bernoulli trial, like a biased coin flip.
166
+ *
167
+ * This is a platform function for the East language, enabling binary random outcomes
168
+ * in East programs running in a browser.
169
+ *
170
+ * @param p - Success probability (0 ≤ p < 1), default 0.5
171
+ * @returns 0 or 1 (as integer)
172
+ *
173
+ * @throws {EastError} When p < 0 or p ≥ 1
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const coinFlip = East.function([], IntegerType, $ => {
178
+ * // Fair coin: 50% chance of 1
179
+ * return Random.bernoulli(0.5);
180
+ * });
181
+ * ```
182
+ *
183
+ * @remarks
184
+ * - Returns 1 with probability p, 0 with probability (1-p)
185
+ * - Mean = p, Variance = p(1-p)
186
+ * - Special case of binomial with n=1
187
+ */
188
+ export declare const random_bernoulli: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
189
+ /**
190
+ * Generates the number of successes in n independent Bernoulli trials.
191
+ *
192
+ * Returns an integer count of successes when performing n independent trials,
193
+ * each with success probability p. Models scenarios like coin flips, pass/fail tests.
194
+ *
195
+ * This is a platform function for the East language, enabling binomial distribution sampling
196
+ * in East programs running in a browser.
197
+ *
198
+ * @param n - Number of trials (integer > 0)
199
+ * @param p - Success probability per trial (0 ≤ p < 1), default 0.5
200
+ * @returns Number of successes (integer in [0, n])
201
+ *
202
+ * @throws {EastError} When n ≤ 0, not an integer, or p < 0 or p ≥ 1
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const heads = East.function([], IntegerType, $ => {
207
+ * // Number of heads in 10 coin flips
208
+ * return Random.binomial(10n, 0.5);
209
+ * });
210
+ * ```
211
+ *
212
+ * @remarks
213
+ * - Mean = n × p, Variance = n × p × (1-p)
214
+ * - Returns value in range [0, n]
215
+ * - Sum of n independent Bernoulli(p) trials
216
+ */
217
+ export declare const random_binomial: import("@elaraai/east").PlatformDefinition<[IntegerType, FloatType], IntegerType>;
218
+ /**
219
+ * Generates the number of trials until the first success.
220
+ *
221
+ * Returns an integer representing the number of independent Bernoulli trials
222
+ * needed to get the first success, where each trial has success probability p.
223
+ * Models scenarios like "how many attempts until success?"
224
+ *
225
+ * This is a platform function for the East language, enabling geometric distribution sampling
226
+ * in East programs running in a browser.
227
+ *
228
+ * @param p - Success probability per trial (0 < p < 1), default 0.5
229
+ * @returns Number of trials until first success (integer ≥ 1)
230
+ *
231
+ * @throws {EastError} When p ≤ 0 or p ≥ 1
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const attempts = East.function([], IntegerType, $ => {
236
+ * // Rolls until getting a 6 (p = 1/6)
237
+ * return Random.geometric(1.0 / 6.0);
238
+ * });
239
+ * ```
240
+ *
241
+ * @remarks
242
+ * - Mean = 1/p, Variance = (1-p)/p²
243
+ * - Always returns integer ≥ 1
244
+ * - Memoryless property like exponential distribution
245
+ * - Uses inverse transform sampling
246
+ */
247
+ export declare const random_geometric: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
248
+ /**
249
+ * Generates the number of events in a fixed interval from a Poisson process.
250
+ *
251
+ * Returns an integer count of events occurring in a fixed interval,
252
+ * where events occur independently at a constant average rate λ (lambda).
253
+ * Commonly used for modeling rare events, arrivals, or counts.
254
+ *
255
+ * This is a platform function for the East language, enabling Poisson distribution sampling
256
+ * in East programs running in a browser.
257
+ *
258
+ * @param lambda - Average rate of events (λ > 0), default 1.0
259
+ * @returns Number of events (integer ≥ 0)
260
+ *
261
+ * @throws {EastError} When lambda ≤ 0
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * const customers = East.function([], IntegerType, $ => {
266
+ * // Average 3 customers per hour
267
+ * return Random.poisson(3.0);
268
+ * });
269
+ * ```
270
+ *
271
+ * @remarks
272
+ * - Mean = λ, Variance = λ
273
+ * - Always returns non-negative integer
274
+ * - Uses inversion method for λ < 10, generative method for λ ≥ 10
275
+ * - Approximates binomial when n is large and p is small
276
+ */
277
+ export declare const random_poisson: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
278
+ /**
279
+ * Generates a random float from a Pareto distribution (power law).
280
+ *
281
+ * Returns a random floating-point number drawn from a Pareto distribution
282
+ * with shape parameter α (alpha). Models phenomena following power laws,
283
+ * like wealth distribution, city sizes, or word frequencies.
284
+ *
285
+ * This is a platform function for the East language, enabling Pareto distribution sampling
286
+ * in East programs running in a browser.
287
+ *
288
+ * @param alpha - Shape parameter (α ≥ 0), default 1.0. Smaller α = heavier tail
289
+ * @returns A random float from Pareto(α) (value ≥ 1.0)
290
+ *
291
+ * @throws {EastError} When alpha < 0
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const wealth = East.function([], FloatType, $ => {
296
+ * // Heavy-tailed distribution (80/20 rule)
297
+ * return Random.pareto(1.16);
298
+ * });
299
+ * ```
300
+ *
301
+ * @remarks
302
+ * - Always returns value ≥ 1.0
303
+ * - Mean = α/(α-1) for α > 1, infinite otherwise
304
+ * - Heavier tail as α decreases
305
+ * - Models "80/20 rule" and power law phenomena
306
+ */
307
+ export declare const random_pareto: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
308
+ /**
309
+ * Generates a random float whose logarithm is normally distributed.
310
+ *
311
+ * Returns a random floating-point number from a log-normal distribution,
312
+ * where ln(X) ~ N(μ, σ²). Commonly used for modeling multiplicative processes,
313
+ * stock prices, or quantities that can't be negative.
314
+ *
315
+ * This is a platform function for the East language, enabling log-normal distribution sampling
316
+ * in East programs running in a browser.
317
+ *
318
+ * @param mu - Mean of underlying normal distribution, default 0.0
319
+ * @param sigma - Standard deviation of underlying normal, default 1.0
320
+ * @returns A random float from LogNormal(μ, σ) (always positive)
321
+ *
322
+ * @example
323
+ * ```ts
324
+ * const stockPrice = East.function([], FloatType, $ => {
325
+ * // Log-normal with ln(X) ~ N(0, 0.2)
326
+ * return Random.logNormal(0.0, 0.2);
327
+ * });
328
+ * ```
329
+ *
330
+ * @remarks
331
+ * - Always returns positive values
332
+ * - If ln(X) ~ N(μ, σ²), then X ~ LogNormal(μ, σ)
333
+ * - Median = exp(μ), Mean = exp(μ + σ²/2)
334
+ * - Right-skewed distribution
335
+ */
336
+ export declare const random_log_normal: import("@elaraai/east").PlatformDefinition<[FloatType, FloatType], FloatType>;
337
+ /**
338
+ * Generates the sum of n independent uniform random variables.
339
+ *
340
+ * Returns the sum of n independent uniform(0,1) random variables.
341
+ * This is the Irwin-Hall distribution. As n increases, approaches
342
+ * normal distribution by Central Limit Theorem.
343
+ *
344
+ * This is a platform function for the East language, enabling Irwin-Hall distribution sampling
345
+ * in East programs running in a browser.
346
+ *
347
+ * @param n - Number of uniform variables to sum (integer ≥ 0), default 1
348
+ * @returns Sum of n uniform(0,1) random variables (float in [0, n])
349
+ *
350
+ * @throws {EastError} When n < 0 or not an integer
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const irwinHall = East.function([], FloatType, $ => {
355
+ * // Sum of 12 uniform variables
356
+ * return Random.irwinHall(12n);
357
+ * });
358
+ * ```
359
+ *
360
+ * @remarks
361
+ * - Range: [0, n]
362
+ * - Mean = n/2, Variance = n/12
363
+ * - Approximates N(n/2, n/12) for large n
364
+ * - Related to Bates distribution (divided by n)
365
+ */
366
+ export declare const random_irwin_hall: import("@elaraai/east").PlatformDefinition<[IntegerType], FloatType>;
367
+ /**
368
+ * Generates the average of n independent uniform random variables.
369
+ *
370
+ * Returns the average of n independent uniform(0,1) random variables.
371
+ * This is the Bates distribution. Approaches normal distribution as
372
+ * n increases (Central Limit Theorem).
373
+ *
374
+ * This is a platform function for the East language, enabling Bates distribution sampling
375
+ * in East programs running in a browser.
376
+ *
377
+ * @param n - Number of uniform variables to average (integer > 0), default 1
378
+ * @returns Average of n uniform(0,1) random variables (float in [0, 1])
379
+ *
380
+ * @throws {EastError} When n ≤ 0 or not an integer
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * const bates = East.function([], FloatType, $ => {
385
+ * // Average of 12 uniform variables (smoother than single uniform)
386
+ * return Random.bates(12n);
387
+ * });
388
+ * ```
389
+ *
390
+ * @remarks
391
+ * - Range: [0, 1]
392
+ * - Mean = 0.5, Variance = 1/(12n)
393
+ * - Approximates N(0.5, 1/(12n)) for large n
394
+ * - More concentrated around 0.5 as n increases
395
+ */
396
+ export declare const random_bates: import("@elaraai/east").PlatformDefinition<[IntegerType], FloatType>;
397
+ /**
398
+ * Seeds the random number generator.
399
+ *
400
+ * Sets the seed for the random number generator, allowing reproducible random sequences.
401
+ * All subsequent random operations will use this seeded RNG until a new seed is set.
402
+ *
403
+ * This is a platform function for the East language, enabling reproducible randomness
404
+ * in East programs running in a browser.
405
+ *
406
+ * @param seed - Seed value (integer)
407
+ * @returns null
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * const seedAndGenerate = East.function([], FloatType, $ => {
412
+ * $(Random.seed(12345n));
413
+ * return Random.uniform(); // Will be reproducible
414
+ * });
415
+ * ```
416
+ *
417
+ * @remarks
418
+ * - IMPORTANT: Seeding switches from cryptographically secure random to a deterministic
419
+ * PRNG (xorshift128+). This is essential for reproducible simulations but should not
420
+ * be used when cryptographic security is required.
421
+ * - Same seed produces same sequence of random numbers, and the same sequence
422
+ * east-node-std produces for it
423
+ * - The seed holds for the implementation that was seeded: each
424
+ * {@link createRandomImpl} (and so each `createWebPlatform()`) starts unseeded
425
+ */
426
+ export declare const random_seed: import("@elaraai/east").PlatformDefinition<[IntegerType], NullType>;
427
+ /**
428
+ * Creates a Random implementation with its own generator, unseeded.
429
+ *
430
+ * Every Random platform function in the returned array draws from one
431
+ * generator that no other implementation shares: it is cryptographically
432
+ * secure until the program calls {@link Random.seed}. A host running one
433
+ * program after another in the same worker creates one per program, so a
434
+ * seed one program set never reaches the next — as each east-node process
435
+ * starts unseeded.
436
+ *
437
+ * @returns The Random platform functions, drawing from a new generator
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * import { East, FloatType } from "@elaraai/east";
442
+ * import { Random, createRandomImpl } from "@elaraai/east-web-std";
443
+ *
444
+ * const draw = East.function([], FloatType, $ => {
445
+ * $(Random.seed(42n));
446
+ * return Random.uniform();
447
+ * });
448
+ *
449
+ * const compiled = East.compile(draw, createRandomImpl());
450
+ * compiled(); // The value east-node-std draws for seed 42
451
+ * ```
452
+ */
453
+ export declare function createRandomImpl(): PlatformFunction[];
454
+ /**
455
+ * Reset {@link RandomImpl}'s generator to cryptographically secure mode.
456
+ * Primarily for testing to avoid test pollution.
457
+ */
458
+ export declare function resetToCryptoRNG(): void;
459
+ /**
460
+ * Browser implementation of the random platform functions, sharing one
461
+ * generator between every program compiled with it.
462
+ *
463
+ * Pass this array to {@link East.compile} to enable random operations, or
464
+ * use {@link createRandomImpl} for a generator of the program's own.
465
+ */
466
+ declare const RandomImpl: PlatformFunction[];
467
+ /**
468
+ * Grouped random platform functions.
469
+ *
470
+ * Provides random number generation and sampling operations for East programs,
471
+ * including multiple probability distributions and collection sampling.
472
+ *
473
+ * @example
474
+ * ```ts
475
+ * import { East, FloatType, IntegerType } from "@elaraai/east";
476
+ * import { Random } from "@elaraai/east-web-std";
477
+ *
478
+ * const rollDice = East.function([], IntegerType, $ => {
479
+ * return Random.range(1n, 6n);
480
+ * });
481
+ *
482
+ * const compiled = East.compile(rollDice, Random.Implementation);
483
+ * const result = compiled(); // Random integer from 1 to 6
484
+ * ```
485
+ */
486
+ export declare const Random: {
487
+ /**
488
+ * Generates a uniform random float in the range [0.0, 1.0).
489
+ *
490
+ * Returns a uniformly distributed random floating-point number greater than or equal to 0.0
491
+ * and strictly less than 1.0. Uses cryptographically secure random number generation.
492
+ *
493
+ * @returns A random float in [0.0, 1.0)
494
+ *
495
+ * @example
496
+ * ```ts
497
+ * const generateRandom = East.function([], FloatType, $ => {
498
+ * return Random.uniform();
499
+ * });
500
+ *
501
+ * const compiled = East.compile(generateRandom, Random.Implementation);
502
+ * const result = compiled(); // e.g., 0.7234891234
503
+ * ```
504
+ */
505
+ readonly uniform: import("@elaraai/east").PlatformDefinition<[], FloatType>;
506
+ /**
507
+ * Generates a random float from a standard normal distribution (mean=0, standard deviation=1).
508
+ *
509
+ * Returns a random floating-point number drawn from a normal (Gaussian) distribution
510
+ * with mean 0.0 and standard deviation 1.0. Use multiplication and addition to scale
511
+ * and shift to different mean/standard deviation.
512
+ *
513
+ * @returns A random float from N(0, 1)
514
+ *
515
+ * @example
516
+ * ```ts
517
+ * const generateNormal = East.function([], FloatType, $ => {
518
+ * const z = $.let(Random.normal());
519
+ * // Scale and shift: z * stddev + mean
520
+ * return z.multiply(2.5).add(10.0); // N(10, 2.5)
521
+ * });
522
+ *
523
+ * const compiled = East.compile(generateNormal, Random.Implementation);
524
+ * const result = compiled(); // e.g., 9.234 (from N(10, 2.5))
525
+ * ```
526
+ */
527
+ readonly normal: import("@elaraai/east").PlatformDefinition<[], FloatType>;
528
+ /**
529
+ * Generates a random integer in the range [min, max] (both endpoints inclusive).
530
+ *
531
+ * Returns a uniformly distributed random integer between min and max (both inclusive).
532
+ * Uses cryptographically secure random number generation.
533
+ *
534
+ * @param min - The minimum value (inclusive)
535
+ * @param max - The maximum value (inclusive, must be >= min)
536
+ * @returns A random integer in [min, max]
537
+ *
538
+ * @throws {EastError} When min > max
539
+ *
540
+ * @example
541
+ * ```ts
542
+ * const rollDice = East.function([], IntegerType, $ => {
543
+ * return Random.range(1n, 6n); // 1-6 inclusive
544
+ * });
545
+ *
546
+ * const compiled = East.compile(rollDice, Random.Implementation);
547
+ * const result = compiled(); // e.g., 4n
548
+ * ```
549
+ */
550
+ readonly range: import("@elaraai/east").PlatformDefinition<[IntegerType, IntegerType], IntegerType>;
551
+ /**
552
+ * Generates a random float from an exponential distribution.
553
+ *
554
+ * Returns a random floating-point number drawn from an exponential distribution
555
+ * with rate parameter lambda (λ). The mean of the distribution is 1/λ.
556
+ * Commonly used for modeling time between events in a Poisson process.
557
+ *
558
+ * @param lambda - Rate parameter (λ > 0), where mean = 1/λ
559
+ * @returns A random float from Exp(λ)
560
+ *
561
+ * @throws {EastError} When lambda <= 0
562
+ *
563
+ * @example
564
+ * ```ts
565
+ * const waitTime = East.function([], FloatType, $ => {
566
+ * // Average wait time of 5 minutes (lambda = 0.2)
567
+ * return Random.exponential(0.2);
568
+ * });
569
+ *
570
+ * const compiled = East.compile(waitTime, Random.Implementation);
571
+ * const result = compiled(); // e.g., 3.7 minutes
572
+ * ```
573
+ */
574
+ readonly exponential: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
575
+ /**
576
+ * Generates a random float from a Weibull distribution.
577
+ *
578
+ * Returns a random floating-point number drawn from a Weibull distribution
579
+ * with shape parameter k. Commonly used for modeling failure rates and lifetime distributions.
580
+ *
581
+ * @param shape - Shape parameter (k > 0). k=1 gives exponential, k>1 increases failure rate
582
+ * @returns A random float from Weibull(k, 1)
583
+ *
584
+ * @throws {EastError} When shape <= 0
585
+ *
586
+ * @example
587
+ * ```ts
588
+ * const lifetime = East.function([], FloatType, $ => {
589
+ * // Shape=2 models wear-out failures
590
+ * return Random.weibull(2.0);
591
+ * });
592
+ *
593
+ * const compiled = East.compile(lifetime, Random.Implementation);
594
+ * const result = compiled(); // e.g., 1.23
595
+ * ```
596
+ */
597
+ readonly weibull: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
598
+ /**
599
+ * Generates a binary random outcome (0 or 1).
600
+ *
601
+ * Returns 0 or 1 based on success probability p. This models a single
602
+ * Bernoulli trial, like a biased coin flip.
603
+ *
604
+ * @param p - Success probability (0 <= p < 1)
605
+ * @returns 0 or 1 (as integer)
606
+ *
607
+ * @throws {EastError} When p < 0 or p >= 1
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * const coinFlip = East.function([], IntegerType, $ => {
612
+ * // Fair coin: 50% chance of 1
613
+ * return Random.bernoulli(0.5);
614
+ * });
615
+ *
616
+ * const compiled = East.compile(coinFlip, Random.Implementation);
617
+ * const result = compiled(); // e.g., 1n or 0n
618
+ * ```
619
+ */
620
+ readonly bernoulli: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
621
+ /**
622
+ * Generates the number of successes in n independent Bernoulli trials.
623
+ *
624
+ * Returns an integer count of successes when performing n independent trials,
625
+ * each with success probability p. Models scenarios like coin flips, pass/fail tests.
626
+ *
627
+ * @param n - Number of trials (integer > 0)
628
+ * @param p - Success probability per trial (0 <= p < 1)
629
+ * @returns Number of successes (integer in [0, n])
630
+ *
631
+ * @throws {EastError} When n <= 0, not an integer, or p < 0 or p >= 1
632
+ *
633
+ * @example
634
+ * ```ts
635
+ * const heads = East.function([], IntegerType, $ => {
636
+ * // Number of heads in 10 coin flips
637
+ * return Random.binomial(10n, 0.5);
638
+ * });
639
+ *
640
+ * const compiled = East.compile(heads, Random.Implementation);
641
+ * const result = compiled(); // e.g., 6n
642
+ * ```
643
+ */
644
+ readonly binomial: import("@elaraai/east").PlatformDefinition<[IntegerType, FloatType], IntegerType>;
645
+ /**
646
+ * Generates the number of trials until the first success.
647
+ *
648
+ * Returns an integer representing the number of independent Bernoulli trials
649
+ * needed to get the first success, where each trial has success probability p.
650
+ * Models scenarios like "how many attempts until success?"
651
+ *
652
+ * @param p - Success probability per trial (0 < p < 1)
653
+ * @returns Number of trials until first success (integer >= 1)
654
+ *
655
+ * @throws {EastError} When p <= 0 or p >= 1
656
+ *
657
+ * @example
658
+ * ```ts
659
+ * const attempts = East.function([], IntegerType, $ => {
660
+ * // Rolls until getting a 6 (p = 1/6)
661
+ * return Random.geometric(1.0 / 6.0);
662
+ * });
663
+ *
664
+ * const compiled = East.compile(attempts, Random.Implementation);
665
+ * const result = compiled(); // e.g., 4n
666
+ * ```
667
+ */
668
+ readonly geometric: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
669
+ /**
670
+ * Generates the number of events in a fixed interval from a Poisson process.
671
+ *
672
+ * Returns an integer count of events occurring in a fixed interval,
673
+ * where events occur independently at a constant average rate λ (lambda).
674
+ * Commonly used for modeling rare events, arrivals, or counts.
675
+ *
676
+ * @param lambda - Average rate of events (λ > 0)
677
+ * @returns Number of events (integer >= 0)
678
+ *
679
+ * @throws {EastError} When lambda <= 0
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * const customers = East.function([], IntegerType, $ => {
684
+ * // Average 3 customers per hour
685
+ * return Random.poisson(3.0);
686
+ * });
687
+ *
688
+ * const compiled = East.compile(customers, Random.Implementation);
689
+ * const result = compiled(); // e.g., 2n
690
+ * ```
691
+ */
692
+ readonly poisson: import("@elaraai/east").PlatformDefinition<[FloatType], IntegerType>;
693
+ /**
694
+ * Generates a random float from a Pareto distribution (power law).
695
+ *
696
+ * Returns a random floating-point number drawn from a Pareto distribution
697
+ * with shape parameter α (alpha). Models phenomena following power laws,
698
+ * like wealth distribution, city sizes, or word frequencies.
699
+ *
700
+ * @param alpha - Shape parameter (α >= 0). Smaller α = heavier tail
701
+ * @returns A random float from Pareto(α) (value >= 1.0)
702
+ *
703
+ * @throws {EastError} When alpha < 0
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * const wealth = East.function([], FloatType, $ => {
708
+ * // Heavy-tailed distribution (80/20 rule)
709
+ * return Random.pareto(1.16);
710
+ * });
711
+ *
712
+ * const compiled = East.compile(wealth, Random.Implementation);
713
+ * const result = compiled(); // e.g., 2.45
714
+ * ```
715
+ */
716
+ readonly pareto: import("@elaraai/east").PlatformDefinition<[FloatType], FloatType>;
717
+ /**
718
+ * Generates a random float whose logarithm is normally distributed.
719
+ *
720
+ * Returns a random floating-point number from a log-normal distribution,
721
+ * where ln(X) ~ N(μ, σ²). Commonly used for modeling multiplicative processes,
722
+ * stock prices, or quantities that can't be negative.
723
+ *
724
+ * @param mu - Mean of underlying normal distribution
725
+ * @param sigma - Standard deviation of underlying normal (must be > 0)
726
+ * @returns A random float from LogNormal(μ, σ) (always positive)
727
+ *
728
+ * @example
729
+ * ```ts
730
+ * const stockPrice = East.function([], FloatType, $ => {
731
+ * // Log-normal with ln(X) ~ N(0, 0.2)
732
+ * return Random.logNormal(0.0, 0.2);
733
+ * });
734
+ *
735
+ * const compiled = East.compile(stockPrice, Random.Implementation);
736
+ * const result = compiled(); // e.g., 1.15
737
+ * ```
738
+ */
739
+ readonly logNormal: import("@elaraai/east").PlatformDefinition<[FloatType, FloatType], FloatType>;
740
+ /**
741
+ * Generates the sum of n independent uniform random variables.
742
+ *
743
+ * Returns the sum of n independent uniform(0,1) random variables.
744
+ * This is the Irwin-Hall distribution. As n increases, approaches
745
+ * normal distribution by Central Limit Theorem.
746
+ *
747
+ * @param n - Number of uniform variables to sum (integer >= 0)
748
+ * @returns Sum of n uniform(0,1) random variables (float in [0, n])
749
+ *
750
+ * @throws {EastError} When n < 0 or not an integer
751
+ *
752
+ * @example
753
+ * ```ts
754
+ * const irwinHall = East.function([], FloatType, $ => {
755
+ * // Sum of 12 uniform variables
756
+ * return Random.irwinHall(12n);
757
+ * });
758
+ *
759
+ * const compiled = East.compile(irwinHall, Random.Implementation);
760
+ * const result = compiled(); // e.g., 6.234 (approximately N(6, 1))
761
+ * ```
762
+ */
763
+ readonly irwinHall: import("@elaraai/east").PlatformDefinition<[IntegerType], FloatType>;
764
+ /**
765
+ * Generates the average of n independent uniform random variables.
766
+ *
767
+ * Returns the average of n independent uniform(0,1) random variables.
768
+ * This is the Bates distribution. Approaches normal distribution as
769
+ * n increases (Central Limit Theorem).
770
+ *
771
+ * @param n - Number of uniform variables to average (integer > 0)
772
+ * @returns Average of n uniform(0,1) random variables (float in [0, 1])
773
+ *
774
+ * @throws {EastError} When n <= 0 or not an integer
775
+ *
776
+ * @example
777
+ * ```ts
778
+ * const bates = East.function([], FloatType, $ => {
779
+ * // Average of 12 uniform variables (smoother than single uniform)
780
+ * return Random.bates(12n);
781
+ * });
782
+ *
783
+ * const compiled = East.compile(bates, Random.Implementation);
784
+ * const result = compiled(); // e.g., 0.523 (approximately N(0.5, 1/144))
785
+ * ```
786
+ */
787
+ readonly bates: import("@elaraai/east").PlatformDefinition<[IntegerType], FloatType>;
788
+ /**
789
+ * Seeds the random number generator.
790
+ *
791
+ * Sets the seed for the random number generator, allowing reproducible random sequences.
792
+ * All subsequent random operations will use this seeded RNG until a new seed is set.
793
+ *
794
+ * @param seed - Seed value (integer)
795
+ * @returns null
796
+ *
797
+ * @example
798
+ * ```ts
799
+ * const seedAndGenerate = East.function([], FloatType, $ => {
800
+ * $(Random.seed(12345n));
801
+ * return Random.uniform(); // Will be reproducible
802
+ * });
803
+ *
804
+ * const compiled = East.compile(seedAndGenerate, Random.Implementation);
805
+ * const result = compiled(); // Same result every time with same seed
806
+ * ```
807
+ *
808
+ * @remarks
809
+ * IMPORTANT: Seeding switches from cryptographically secure random to a deterministic
810
+ * PRNG (xorshift128+). Essential for reproducible simulations. A seed gives the
811
+ * sequence east-node-std gives for it.
812
+ */
813
+ readonly seed: import("@elaraai/east").PlatformDefinition<[IntegerType], NullType>;
814
+ /**
815
+ * Browser implementation of random platform functions.
816
+ *
817
+ * Pass this to {@link East.compile} to enable random operations.
818
+ */
819
+ readonly Implementation: PlatformFunction[];
820
+ };
821
+ export { RandomImpl, XorShift128RNG };
822
+ //# sourceMappingURL=random.d.ts.map