@elaraai/east-node-std 0.0.1-beta.0

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