isaacscript-common 71.2.1 → 72.0.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 (80) hide show
  1. package/dist/index.rollup.d.ts +229 -96
  2. package/dist/isaacscript-common.lua +10 -127
  3. package/dist/src/classes/features/other/CustomItemPools.d.ts +7 -3
  4. package/dist/src/classes/features/other/CustomItemPools.d.ts.map +1 -1
  5. package/dist/src/classes/features/other/CustomItemPools.lua +1 -6
  6. package/dist/src/classes/features/other/DeployJSONRoom.d.ts +7 -3
  7. package/dist/src/classes/features/other/DeployJSONRoom.d.ts.map +1 -1
  8. package/dist/src/classes/features/other/DeployJSONRoom.lua +1 -5
  9. package/dist/src/classes/features/other/ModdedElementSets.d.ts +35 -15
  10. package/dist/src/classes/features/other/ModdedElementSets.d.ts.map +1 -1
  11. package/dist/src/classes/features/other/ModdedElementSets.lua +0 -17
  12. package/dist/src/classes/features/other/SpawnCollectible.d.ts +14 -6
  13. package/dist/src/classes/features/other/SpawnCollectible.d.ts.map +1 -1
  14. package/dist/src/classes/features/other/SpawnCollectible.lua +0 -8
  15. package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts +8 -4
  16. package/dist/src/classes/features/other/SpawnRockAltRewards.d.ts.map +1 -1
  17. package/dist/src/classes/features/other/SpawnRockAltRewards.lua +0 -4
  18. package/dist/src/classes/features/other/customStages/utils.d.ts +2 -2
  19. package/dist/src/classes/features/other/customStages/utils.d.ts.map +1 -1
  20. package/dist/src/classes/features/other/customStages/utils.lua +0 -8
  21. package/dist/src/classes/features/other/extraConsoleCommands/commands.lua +2 -2
  22. package/dist/src/functions/array.d.ts +35 -15
  23. package/dist/src/functions/array.d.ts.map +1 -1
  24. package/dist/src/functions/array.lua +30 -26
  25. package/dist/src/functions/color.d.ts +8 -4
  26. package/dist/src/functions/color.d.ts.map +1 -1
  27. package/dist/src/functions/color.lua +7 -7
  28. package/dist/src/functions/enums.d.ts +6 -3
  29. package/dist/src/functions/enums.d.ts.map +1 -1
  30. package/dist/src/functions/enums.lua +5 -7
  31. package/dist/src/functions/itemPool.d.ts +8 -1
  32. package/dist/src/functions/itemPool.d.ts.map +1 -1
  33. package/dist/src/functions/itemPool.lua +9 -2
  34. package/dist/src/functions/jsonRoom.d.ts +13 -6
  35. package/dist/src/functions/jsonRoom.d.ts.map +1 -1
  36. package/dist/src/functions/jsonRoom.lua +11 -12
  37. package/dist/src/functions/kColor.d.ts +8 -4
  38. package/dist/src/functions/kColor.d.ts.map +1 -1
  39. package/dist/src/functions/kColor.lua +7 -7
  40. package/dist/src/functions/levelGrid.d.ts +12 -5
  41. package/dist/src/functions/levelGrid.d.ts.map +1 -1
  42. package/dist/src/functions/levelGrid.lua +10 -7
  43. package/dist/src/functions/random.d.ts +22 -13
  44. package/dist/src/functions/random.d.ts.map +1 -1
  45. package/dist/src/functions/random.lua +19 -20
  46. package/dist/src/functions/rng.d.ts +1 -1
  47. package/dist/src/functions/rng.lua +1 -1
  48. package/dist/src/functions/set.d.ts +7 -3
  49. package/dist/src/functions/set.d.ts.map +1 -1
  50. package/dist/src/functions/set.lua +6 -7
  51. package/dist/src/functions/spawnCollectible.d.ts +13 -5
  52. package/dist/src/functions/spawnCollectible.d.ts.map +1 -1
  53. package/dist/src/functions/spawnCollectible.lua +14 -9
  54. package/dist/src/functions/vector.d.ts +7 -3
  55. package/dist/src/functions/vector.d.ts.map +1 -1
  56. package/dist/src/functions/vector.lua +6 -6
  57. package/dist/src/functions/weighted.d.ts +18 -2
  58. package/dist/src/functions/weighted.d.ts.map +1 -1
  59. package/dist/src/functions/weighted.lua +16 -8
  60. package/package.json +1 -1
  61. package/src/classes/features/other/CustomItemPools.ts +7 -4
  62. package/src/classes/features/other/DeployJSONRoom.ts +9 -5
  63. package/src/classes/features/other/ModdedElementSets.ts +37 -16
  64. package/src/classes/features/other/SpawnCollectible.ts +14 -7
  65. package/src/classes/features/other/SpawnRockAltRewards.ts +9 -5
  66. package/src/classes/features/other/customStages/utils.ts +2 -3
  67. package/src/classes/features/other/extraConsoleCommands/commands.ts +2 -2
  68. package/src/functions/array.ts +36 -16
  69. package/src/functions/color.ts +9 -5
  70. package/src/functions/enums.ts +6 -4
  71. package/src/functions/itemPool.ts +11 -2
  72. package/src/functions/jsonRoom.ts +13 -7
  73. package/src/functions/kColor.ts +9 -5
  74. package/src/functions/levelGrid.ts +13 -6
  75. package/src/functions/random.ts +23 -14
  76. package/src/functions/rng.ts +1 -1
  77. package/src/functions/set.ts +7 -4
  78. package/src/functions/spawnCollectible.ts +17 -5
  79. package/src/functions/vector.ts +8 -4
  80. package/src/functions/weighted.ts +18 -3
@@ -1,7 +1,6 @@
1
1
  import { sumArray } from "../../../../functions/array";
2
2
  import { log } from "../../../../functions/log";
3
3
  import { getRandomFloat } from "../../../../functions/random";
4
- import { getRandomSeed } from "../../../../functions/rng";
5
4
  import type {
6
5
  CustomStageBossPoolEntry,
7
6
  CustomStageRoomMetadata,
@@ -16,7 +15,7 @@ import type {
16
15
  */
17
16
  export function getRandomCustomStageRoom(
18
17
  roomsMetadata: readonly CustomStageRoomMetadata[],
19
- seedOrRNG: Seed | RNG = getRandomSeed(),
18
+ seedOrRNG: Seed | RNG | undefined,
20
19
  verbose = false,
21
20
  ): CustomStageRoomMetadata {
22
21
  const totalWeight = getTotalWeightOfCustomStageRooms(roomsMetadata);
@@ -59,7 +58,7 @@ function getCustomStageRoomWithChosenWeight(
59
58
  export function getRandomBossRoomFromPool(
60
59
  roomsMetadata: readonly CustomStageRoomMetadata[],
61
60
  bossPool: readonly CustomStageBossPoolEntry[],
62
- seedOrRNG: Seed | RNG = getRandomSeed(),
61
+ seedOrRNG: Seed | RNG | undefined,
63
62
  verbose = false,
64
63
  ): CustomStageRoomMetadata {
65
64
  const totalWeight = getTotalWeightOfBossPool(bossPool);
@@ -1470,7 +1470,7 @@ export function spawnCollectible(params: string): void {
1470
1470
 
1471
1471
  const roomClass = game.GetRoom();
1472
1472
  const centerPos = roomClass.GetCenterPos();
1473
- spawnCollectibleUnsafe(collectibleType, centerPos);
1473
+ spawnCollectibleUnsafe(collectibleType, centerPos, undefined);
1474
1474
  }
1475
1475
 
1476
1476
  /**
@@ -1515,7 +1515,7 @@ export function spawnCollectibleAt(params: string): void {
1515
1515
  }
1516
1516
 
1517
1517
  const collectibleType = asCollectibleType(collectibleTypeNumber);
1518
- spawnCollectibleUnsafe(collectibleType, gridIndex);
1518
+ spawnCollectibleUnsafe(collectibleType, gridIndex, undefined);
1519
1519
  }
1520
1520
 
1521
1521
  /** Alias for the `spawnGoldenTrinket` command. */
@@ -1,7 +1,7 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
2
  import type { WidenLiteral } from "../types/WidenLiteral";
3
3
  import { getRandomInt } from "./random";
4
- import { getRandomSeed, isRNG, newRNG } from "./rng";
4
+ import { isRNG, newRNG } from "./rng";
5
5
  import { isNumber, isTable } from "./types";
6
6
  import { assertDefined, eRange } from "./utils";
7
7
 
@@ -393,14 +393,18 @@ export function getLowestArrayElement(array: number[]): number | undefined {
393
393
  /**
394
394
  * Helper function to get a random element from the provided array.
395
395
  *
396
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
397
+ * parameter.
398
+ *
396
399
  * @param array The array to get an element from.
397
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
398
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
400
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
401
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
402
+ * a random seed.
399
403
  * @param exceptions Optional. An array of elements to skip over if selected.
400
404
  */
401
405
  export function getRandomArrayElement<T>(
402
406
  array: T[] | readonly T[],
403
- seedOrRNG: Seed | RNG = getRandomSeed(),
407
+ seedOrRNG: Seed | RNG | undefined,
404
408
  exceptions: T[] | readonly T[] = [],
405
409
  ): T {
406
410
  if (array.length === 0) {
@@ -425,14 +429,18 @@ export function getRandomArrayElement<T>(
425
429
  * Helper function to get a random element from the provided array. Once the random element is
426
430
  * decided, it is then removed from the array (in-place).
427
431
  *
432
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
433
+ * parameter.
434
+ *
428
435
  * @param array The array to get an element from.
429
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
430
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
436
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
437
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
438
+ * a random seed.
431
439
  * @param exceptions Optional. An array of elements to skip over if selected.
432
440
  */
433
441
  export function getRandomArrayElementAndRemove<T>(
434
442
  array: T[],
435
- seedOrRNG: Seed | RNG = getRandomSeed(),
443
+ seedOrRNG: Seed | RNG | undefined,
436
444
  exceptions: T[] | readonly T[] = [],
437
445
  ): T {
438
446
  const randomArrayElement = getRandomArrayElement(
@@ -447,15 +455,19 @@ export function getRandomArrayElementAndRemove<T>(
447
455
  /**
448
456
  * Helper function to get a random index from the provided array.
449
457
  *
458
+ * If you want to get an unseeded index, you must explicitly pass `undefined` to the `seedOrRNG`
459
+ * parameter.
460
+ *
450
461
  * @param array The array to get the index from.
451
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
452
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
462
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
463
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
464
+ * a random seed.
453
465
  * @param exceptions Optional. An array of indexes that will be skipped over when getting the random
454
466
  * index. Default is an empty array.
455
467
  */
456
468
  export function getRandomArrayIndex<T>(
457
469
  array: T[] | readonly T[],
458
- seedOrRNG: Seed | RNG = getRandomSeed(),
470
+ seedOrRNG: Seed | RNG | undefined,
459
471
  exceptions: int[] | readonly int[] = [],
460
472
  ): int {
461
473
  if (array.length === 0) {
@@ -570,15 +582,19 @@ export function setAllArrayElements<T>(array: T[], value: T): void {
570
582
  /**
571
583
  * Shallow copies and shuffles the array using the Fisher-Yates algorithm. Returns the copied array.
572
584
  *
585
+ * If you want an unseeded shuffle, you must explicitly pass `undefined` to the `seedOrRNG`
586
+ * parameter.
587
+ *
573
588
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
574
589
  *
575
590
  * @param originalArray The array to shuffle.
576
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
577
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
591
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
592
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
593
+ * a random seed.
578
594
  */
579
595
  export function shuffleArray<T>(
580
596
  originalArray: T[] | readonly T[],
581
- seedOrRNG: Seed | RNG = getRandomSeed(),
597
+ seedOrRNG: Seed | RNG | undefined,
582
598
  ): T[] {
583
599
  const array = copyArray(originalArray);
584
600
  shuffleArrayInPlace(array, seedOrRNG);
@@ -589,15 +605,19 @@ export function shuffleArray<T>(
589
605
  /**
590
606
  * Shuffles the provided array in-place using the Fisher-Yates algorithm.
591
607
  *
608
+ * If you want an unseeded shuffle, you must explicitly pass `undefined` to the `seedOrRNG`
609
+ * parameter.
610
+ *
592
611
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
593
612
  *
594
613
  * @param array The array to shuffle.
595
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
596
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
614
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
615
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
616
+ * a random seed.
597
617
  */
598
618
  export function shuffleArrayInPlace<T>(
599
619
  array: T[],
600
- seedOrRNG: Seed | RNG = getRandomSeed(),
620
+ seedOrRNG: Seed | RNG | undefined,
601
621
  ): void {
602
622
  let currentIndex = array.length;
603
623
 
@@ -2,7 +2,7 @@ import type { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
3
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
4
4
  import { getRandom } from "./random";
5
- import { getRandomSeed, isRNG, newRNG } from "./rng";
5
+ import { isRNG, newRNG } from "./rng";
6
6
  import {
7
7
  copyUserdataValuesToTable,
8
8
  getNumbersFromTable,
@@ -76,14 +76,18 @@ export function deserializeColor(color: SerializedColor): Color {
76
76
  }
77
77
 
78
78
  /**
79
- * Helper function to get a random color.
79
+ * Helper function to get a random `Color` object.
80
80
  *
81
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
82
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
81
+ * If you want to generate an unseeded object, you must explicitly pass `undefined` to the
82
+ * `seedOrRNG` parameter.
83
+ *
84
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
85
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
86
+ * a random seed.
83
87
  * @param alpha Optional. The alpha value to use. Default is 1.
84
88
  */
85
89
  export function getRandomColor(
86
- seedOrRNG: Seed | RNG = getRandomSeed(),
90
+ seedOrRNG: Seed | RNG | undefined,
87
91
  alpha = 1,
88
92
  ): Readonly<Color> {
89
93
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
@@ -1,6 +1,5 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
2
  import { getRandomArrayElement } from "./array";
3
- import { getRandomSeed } from "./rng";
4
3
  import { isNumber, isString } from "./types";
5
4
  import { assertDefined, iRange } from "./utils";
6
5
 
@@ -176,14 +175,17 @@ export function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T] {
176
175
  /**
177
176
  * Helper function to get a random value from the provided enum.
178
177
  *
178
+ * If you want an unseeded value, you must explicitly pass `undefined` to the `seedOrRNG` parameter.
179
+ *
179
180
  * @param transpiledEnum The enum to get the value from.
180
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
181
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
181
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
182
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
183
+ * a random seed.
182
184
  * @param exceptions Optional. An array of elements to skip over if selected.
183
185
  */
184
186
  export function getRandomEnumValue<T>(
185
187
  transpiledEnum: T,
186
- seedOrRNG: Seed | RNG = getRandomSeed(),
188
+ seedOrRNG: Seed | RNG | undefined,
187
189
  exceptions: Array<T[keyof T]> | ReadonlyArray<T[keyof T]> = [],
188
190
  ): T[keyof T] {
189
191
  const enumValues = getEnumValues(transpiledEnum);
@@ -45,12 +45,21 @@ const GREED_MODE_ITEM_POOL_TYPES: readonly ItemPoolType[] = arrayRemove(
45
45
  * Helper function to get a random item pool. This is not as simple as getting a random value from
46
46
  * the `ItemPoolType` enum, since `ItemPoolType.SHELL_GAME` (7) is not a real item pool and the
47
47
  * Greed Mode item pools should be excluded if not playing in Greed Mode.
48
+ *
49
+ * If you want to get an unseeded item pool, you must explicitly pass `undefined` to the `seedOrRNG`
50
+ * parameter.
51
+ *
52
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
53
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
54
+ * a random seed.
48
55
  */
49
- export function getRandomItemPool(): ItemPoolType {
56
+ export function getRandomItemPool(
57
+ seedOrRNG: Seed | RNG | undefined,
58
+ ): ItemPoolType {
50
59
  const itemPoolTypes = game.IsGreedMode()
51
60
  ? GREED_MODE_ITEM_POOL_TYPES
52
61
  : NORMAL_MODE_ITEM_POOL_TYPES;
53
- return getRandomArrayElement(itemPoolTypes);
62
+ return getRandomArrayElement(itemPoolTypes, seedOrRNG);
54
63
  }
55
64
 
56
65
  /**
@@ -7,7 +7,6 @@ import { isEnumValue } from "./enums";
7
7
  import { addFlag } from "./flag";
8
8
  import { log } from "./log";
9
9
  import { getRandomFloat } from "./random";
10
- import { getRandomSeed } from "./rng";
11
10
  import { assertDefined } from "./utils";
12
11
 
13
12
  /** This represents either a `JSONRoom` or a `JSONEntity`. */
@@ -141,15 +140,19 @@ export function getJSONRoomsOfSubType(
141
140
  * properly account for each room weight using the algorithm from:
142
141
  * https://stackoverflow.com/questions/1761626/weighted-random-numbers
143
142
  *
143
+ * If you want an unseeded entity, you must explicitly pass `undefined` to the `seedOrRNG`
144
+ * parameter.
145
+ *
144
146
  * @param jsonEntities The array of entities to randomly choose between.
145
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
146
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
147
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
148
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
149
+ * a random seed.
147
150
  * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
148
151
  * what the function is doing. Default is false.
149
152
  */
150
153
  export function getRandomJSONEntity(
151
154
  jsonEntities: JSONEntity[],
152
- seedOrRNG: Seed | RNG = getRandomSeed(),
155
+ seedOrRNG: Seed | RNG | undefined,
153
156
  verbose = false,
154
157
  ): JSONEntity {
155
158
  const totalWeight = getTotalWeightOfJSONObject(jsonEntities);
@@ -183,15 +186,18 @@ export function getRandomJSONEntity(
183
186
  * properly account for each room weight using the algorithm from:
184
187
  * https://stackoverflow.com/questions/1761626/weighted-random-numbers
185
188
  *
189
+ * If you want an unseeded room, you must explicitly pass `undefined` to the `seedOrRNG` parameter.
190
+ *
186
191
  * @param jsonRooms The array of rooms to randomly choose between.
187
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
188
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
192
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
193
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
194
+ * a random seed.
189
195
  * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
190
196
  * what the function is doing. Default is false.
191
197
  */
192
198
  export function getRandomJSONRoom(
193
199
  jsonRooms: JSONRoom[],
194
- seedOrRNG: Seed | RNG = getRandomSeed(),
200
+ seedOrRNG: Seed | RNG | undefined,
195
201
  verbose = false,
196
202
  ): JSONRoom {
197
203
  const totalWeight = getTotalWeightOfJSONObject(jsonRooms);
@@ -2,7 +2,7 @@ import type { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
3
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
4
4
  import { getRandom } from "./random";
5
- import { getRandomSeed, isRNG, newRNG } from "./rng";
5
+ import { isRNG, newRNG } from "./rng";
6
6
  import {
7
7
  copyUserdataValuesToTable,
8
8
  getNumbersFromTable,
@@ -64,14 +64,18 @@ export function deserializeKColor(kColor: SerializedKColor): KColor {
64
64
  }
65
65
 
66
66
  /**
67
- * Helper function to get a random color.
67
+ * Helper function to get a random `KColor` object (for use in fonts).
68
68
  *
69
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
70
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
69
+ * If you want to generate an unseeded object, you must explicitly pass `undefined` to the
70
+ * `seedOrRNG` parameter.
71
+ *
72
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
73
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
74
+ * a random seed.
71
75
  * @param alpha Optional. The alpha value to use. Default is 1.
72
76
  */
73
77
  export function getRandomKColor(
74
- seedOrRNG: Seed | RNG = getRandomSeed(),
78
+ seedOrRNG: Seed | RNG | undefined,
75
79
  alpha = 1,
76
80
  ): Readonly<KColor> {
77
81
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
@@ -25,7 +25,7 @@ import { getRandomArrayElement } from "./array";
25
25
  import { doorSlotToDoorSlotFlag } from "./doors";
26
26
  import { addFlag, hasFlag, removeFlag } from "./flag";
27
27
  import { copyMap } from "./map";
28
- import { getRandomSeed, isRNG, newRNG } from "./rng";
28
+ import { isRNG, newRNG } from "./rng";
29
29
  import {
30
30
  getRoomAllowedDoors,
31
31
  getRoomData,
@@ -126,8 +126,12 @@ export function getAllRoomGridIndexes(): readonly int[] {
126
126
  * some floors will not have any valid spots. If this is the case, this function will return
127
127
  * undefined.
128
128
  *
129
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
130
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
129
+ * If you want to get an unseeded room, you must explicitly pass `undefined` to the `seedOrRNG`
130
+ * parameter.
131
+ *
132
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
133
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
134
+ * a random seed.
131
135
  * @param ensureDeadEnd Optional. Whether to pick a valid dead end attached to a normal room. If
132
136
  * false, the function will randomly pick from any valid location that would
133
137
  * have a red door.
@@ -135,7 +139,7 @@ export function getAllRoomGridIndexes(): readonly int[] {
135
139
  * undefined.
136
140
  */
137
141
  export function getNewRoomCandidate(
138
- seedOrRNG: Seed | RNG = getRandomSeed(),
142
+ seedOrRNG: Seed | RNG | undefined,
139
143
  ensureDeadEnd = true,
140
144
  ):
141
145
  | {
@@ -521,9 +525,12 @@ export function isRoomInsideGrid(roomGridIndex?: int): boolean {
521
525
  /**
522
526
  * Helper function to generate a new room on the floor.
523
527
  *
528
+ * If you want to generate an unseeded room, you must explicitly pass `undefined` to the `seedOrRNG`
529
+ * parameter.
530
+ *
524
531
  * Under the hood, this function uses the `Level.MakeRedRoomDoor` method to create the room.
525
532
  *
526
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
533
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
527
534
  * `RNG.Next` method will be called. Default is `Level.GetDungeonPlacementSeed`.
528
535
  * Note that the RNG is only used to select the random location to put the room on
529
536
  * the floor; it does not influence the randomly chosen room contents. (That is
@@ -538,7 +545,7 @@ export function isRoomInsideGrid(roomGridIndex?: int): boolean {
538
545
  * place a room.
539
546
  */
540
547
  export function newRoom(
541
- seedOrRNG?: Seed | RNG,
548
+ seedOrRNG: Seed | RNG | undefined,
542
549
  ensureDeadEnd = true,
543
550
  customRoomData?: RoomConfig,
544
551
  ): int | undefined {
@@ -1,14 +1,18 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
- import { getRandomSeed, isRNG, newRNG } from "./rng";
2
+ import { isRNG, newRNG } from "./rng";
3
3
 
4
4
  /**
5
5
  * Returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on the high
6
6
  * end. (This is because the `RNG.RandomFloat` method will never return a value of exactly 1.)
7
7
  *
8
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
9
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
8
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
9
+ * `seedOrRNG` parameter.
10
+ *
11
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
12
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
13
+ * a random seed.
10
14
  */
11
- export function getRandom(seedOrRNG: Seed | RNG = getRandomSeed()): float {
15
+ export function getRandom(seedOrRNG: Seed | RNG | undefined): float {
12
16
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
13
17
  return rng.RandomFloat();
14
18
  }
@@ -19,18 +23,22 @@ export function getRandom(seedOrRNG: Seed | RNG = getRandomSeed()): float {
19
23
  * For example:
20
24
  *
21
25
  * ```ts
22
- * const realNumberBetweenOneAndThree = getRandomFloat(1, 3);
26
+ * const realNumberBetweenOneAndThree = getRandomFloat(1, 3, undefined);
23
27
  * ```
24
28
  *
29
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
30
+ * `seedOrRNG` parameter.
31
+ *
25
32
  * @param min The lower bound for the random number (inclusive).
26
33
  * @param max The upper bound for the random number (exclusive).
27
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
28
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
34
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
35
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
36
+ * a random seed.
29
37
  */
30
38
  export function getRandomFloat(
31
39
  min: int,
32
40
  max: int,
33
- seedOrRNG: Seed | RNG = getRandomSeed(),
41
+ seedOrRNG: Seed | RNG | undefined,
34
42
  ): float {
35
43
  if (min > max) {
36
44
  const oldMin = min;
@@ -46,19 +54,20 @@ export function getRandomFloat(
46
54
  /**
47
55
  * Returns a random integer between min and max. It is inclusive on both ends.
48
56
  *
49
- * Note that this function will run the `Next` method on the `RNG` object before returning the
50
- * random number.
51
- *
52
57
  * For example:
53
58
  *
54
59
  * ```ts
55
60
  * const oneTwoOrThree = getRandomInt(1, 3);
56
61
  * ```
57
62
  *
63
+ * If you want to generate an unseeded number, you must explicitly pass `undefined` to the
64
+ * `seedOrRNG` parameter.
65
+ *
58
66
  * @param min The lower bound for the random number (inclusive).
59
67
  * @param max The upper bound for the random number (inclusive).
60
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
61
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
68
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
69
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
70
+ * a random seed.
62
71
  * @param exceptions Optional. An array of elements that will be skipped over when getting the
63
72
  * random integer. For example, a min of 1, a max of 4, and an exceptions array of
64
73
  * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
@@ -67,7 +76,7 @@ export function getRandomFloat(
67
76
  export function getRandomInt(
68
77
  min: int,
69
78
  max: int,
70
- seedOrRNG: Seed | RNG = getRandomSeed(),
79
+ seedOrRNG: Seed | RNG | undefined,
71
80
  exceptions: int[] | readonly int[] = [],
72
81
  ): int {
73
82
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
@@ -86,7 +86,7 @@ export function isSerializedRNG(object: unknown): object is SerializedRNG {
86
86
  /**
87
87
  * Helper function to initialize a new RNG object using Blade's recommended shift index.
88
88
  *
89
- * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
89
+ * @param seed Optional. The seed to initialize it with. Default is a random seed.
90
90
  */
91
91
  export function newRNG(seed = getRandomSeed()): RNG {
92
92
  const rng = RNG();
@@ -1,6 +1,5 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
2
  import { getArrayCombinations, getRandomArrayElement, sumArray } from "./array";
3
- import { getRandomSeed } from "./rng";
4
3
  import { isPrimitive } from "./types";
5
4
 
6
5
  /**
@@ -68,14 +67,18 @@ export function deleteSetsFromSet<T>(
68
67
  /**
69
68
  * Helper function to get a random element from the provided set.
70
69
  *
70
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
71
+ * parameter.
72
+ *
71
73
  * @param set The set to get an element from.
72
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
73
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
74
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
75
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
76
+ * a random seed.
74
77
  * @param exceptions Optional. An array of elements to skip over if selected.
75
78
  */
76
79
  export function getRandomSetElement<T>(
77
80
  set: Set<T> | ReadonlySet<T>,
78
- seedOrRNG: Seed | RNG = getRandomSeed(),
81
+ seedOrRNG: Seed | RNG | undefined,
79
82
  exceptions: T[] | readonly T[] = [],
80
83
  ): T {
81
84
  const array = getSortedSetValues(set);
@@ -20,10 +20,14 @@ import { getRandomSeed, isRNG } from "./rng";
20
20
  * Isaac's rotation mechanic. To handle that, use the `spawnCollectible` helper function instead
21
21
  * (which is provided by `ISCFeature.SPAWN_COLLECTIBLE`).
22
22
  *
23
+ * If you want to spawn an unseeded collectible, you must explicitly pass `undefined` to the
24
+ * `seedOrRNG` parameter.
25
+ *
23
26
  * @param collectibleType The collectible type to spawn.
24
27
  * @param positionOrGridIndex The position or grid index to spawn the collectible at.
25
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
26
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
28
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
29
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
30
+ * a random seed.
27
31
  * @param options Optional. Set to true to make the collectible a "There's Options" style
28
32
  * collectible. Default is false.
29
33
  * @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
@@ -33,11 +37,15 @@ import { getRandomSeed, isRNG } from "./rng";
33
37
  export function spawnCollectibleUnsafe(
34
38
  collectibleType: CollectibleType,
35
39
  positionOrGridIndex: Vector | int,
36
- seedOrRNG: Seed | RNG = getRandomSeed(),
40
+ seedOrRNG: Seed | RNG | undefined,
37
41
  options = false,
38
42
  forceFreeItem = false,
39
43
  spawner?: Entity,
40
44
  ): EntityPickupCollectible {
45
+ if (seedOrRNG === undefined) {
46
+ seedOrRNG = getRandomSeed();
47
+ }
48
+
41
49
  const seed = isRNG(seedOrRNG) ? seedOrRNG.Next() : seedOrRNG;
42
50
  const collectible = spawnPickupWithSeed(
43
51
  PickupVariant.COLLECTIBLE,
@@ -82,13 +90,17 @@ export function spawnCollectibleUnsafe(
82
90
  * Onion because it is a quest collectible and quest collectibles will prevent Damocles from
83
91
  * duplicating the pedestal.)
84
92
  *
93
+ * If you want to spawn an unseeded collectible, you must explicitly pass `undefined` to the
94
+ * `seedOrRNG` parameter.
95
+ *
85
96
  * @param positionOrGridIndex The position or grid index to spawn the empty collectible at.
86
97
  * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
87
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
98
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
99
+ * a random seed.
88
100
  */
89
101
  export function spawnEmptyCollectible(
90
102
  positionOrGridIndex: Vector | int,
91
- seedOrRNG: Seed | RNG = getRandomSeed(),
103
+ seedOrRNG: Seed | RNG | undefined,
92
104
  ): EntityPickup {
93
105
  const collectible = spawnCollectibleUnsafe(
94
106
  CollectibleType.BROKEN_SHOVEL_1,
@@ -6,7 +6,7 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
6
6
  import { angleToDirection } from "./direction";
7
7
  import { isIsaacAPIClassOfType, isaacAPIClassEquals } from "./isaacAPIClass";
8
8
  import { getRandomFloat } from "./random";
9
- import { getRandomSeed, isRNG, newRNG } from "./rng";
9
+ import { isRNG, newRNG } from "./rng";
10
10
  import {
11
11
  copyUserdataValuesToTable,
12
12
  getNumbersFromTable,
@@ -109,11 +109,15 @@ export function getClosestVectorTo(
109
109
  *
110
110
  * Use this over the `RandomVector` function when you need the vector to be seeded.
111
111
  *
112
- * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
113
- * `RNG.Next` method will be called. Default is `getRandomSeed()`.
112
+ * If you want to generate an unseeded vector, you must explicitly pass `undefined` to the
113
+ * `seedOrRNG` parameter.
114
+ *
115
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
116
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
117
+ * a random seed.
114
118
  */
115
119
  export function getRandomVector(
116
- seedOrRNG: Seed | RNG = getRandomSeed(),
120
+ seedOrRNG: Seed | RNG | undefined,
117
121
  ): Readonly<Vector> {
118
122
  const rng = isRNG(seedOrRNG) ? seedOrRNG : newRNG(seedOrRNG);
119
123
 
@@ -1,17 +1,24 @@
1
1
  import type { WeightedArray } from "../types/WeightedArray";
2
2
  import { sumArray } from "./array";
3
3
  import { getRandomFloat } from "./random";
4
- import { getRandomSeed } from "./rng";
5
4
  import { assertDefined } from "./utils";
6
5
 
7
6
  /**
8
7
  * Get a random value from a `WeightedArray`. (A `WeightedArray` is an array of tuples, where the
9
8
  * first element in the tuple is a value, and the second element in the tuple is a float
10
9
  * corresponding to the value's weight.)
10
+ *
11
+ * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
12
+ * parameter.
13
+ *
14
+ * @param weightedArray The array to pick from.
15
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
16
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
17
+ * a random seed.
11
18
  */
12
19
  export function getRandomFromWeightedArray<T>(
13
20
  weightedArray: WeightedArray<T>,
14
- seedOrRNG: Seed | RNG = getRandomSeed(),
21
+ seedOrRNG: Seed | RNG | undefined,
15
22
  ): T {
16
23
  const randomIndex = getRandomIndexFromWeightedArray(weightedArray, seedOrRNG);
17
24
 
@@ -28,10 +35,18 @@ export function getRandomFromWeightedArray<T>(
28
35
  * Get a random index from a `WeightedArray`. (A `WeightedArray` is an array of tuples, where the
29
36
  * first element in the tuple is a value, and the second element in the tuple is a float
30
37
  * corresponding to the value's weight.)
38
+ *
39
+ * If you want to get an unseeded index, you must explicitly pass `undefined` to the `seedOrRNG`
40
+ * parameter.
41
+ *
42
+ * @param weightedArray The array to pick from.
43
+ * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
44
+ * `RNG.Next` method will be called. If `undefined` is provided, it will default to
45
+ * a random seed.
31
46
  */
32
47
  export function getRandomIndexFromWeightedArray<T>(
33
48
  weightedArray: WeightedArray<T>,
34
- seedOrRNG: Seed | RNG = getRandomSeed(),
49
+ seedOrRNG: Seed | RNG | undefined,
35
50
  ): int {
36
51
  if (weightedArray.length === 0) {
37
52
  error(