isaacscript-common 5.0.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/functions/array.d.ts +3 -1
- package/functions/array.lua +13 -2
- package/functions/random.d.ts +2 -1
- package/functions/random.lua +3 -2
- package/package.json +1 -1
package/functions/array.d.ts
CHANGED
|
@@ -117,8 +117,10 @@ export declare function getRandomArrayElementAndRemove<T>(array: T[], seedOrRNG?
|
|
|
117
117
|
* @param array The array to get the index from.
|
|
118
118
|
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
119
119
|
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
120
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
121
|
+
* index. Default is an empty array.
|
|
120
122
|
*/
|
|
121
|
-
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG): int;
|
|
123
|
+
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
|
|
122
124
|
/**
|
|
123
125
|
* Initializes an array with all elements containing the specified default value.
|
|
124
126
|
*
|
package/functions/array.lua
CHANGED
|
@@ -32,14 +32,25 @@ local ____repeat = ____utils["repeat"]
|
|
|
32
32
|
-- @param array The array to get the index from.
|
|
33
33
|
-- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
34
34
|
-- `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
35
|
-
|
|
35
|
+
-- @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
36
|
+
-- index. Default is an empty array.
|
|
37
|
+
function ____exports.getRandomArrayIndex(self, array, seedOrRNG, exceptions)
|
|
36
38
|
if seedOrRNG == nil then
|
|
37
39
|
seedOrRNG = getRandomSeed(nil)
|
|
38
40
|
end
|
|
41
|
+
if exceptions == nil then
|
|
42
|
+
exceptions = {}
|
|
43
|
+
end
|
|
39
44
|
if #array == 0 then
|
|
40
45
|
error("Failed to get a random array index since the provided array is empty.")
|
|
41
46
|
end
|
|
42
|
-
return getRandomInt(
|
|
47
|
+
return getRandomInt(
|
|
48
|
+
nil,
|
|
49
|
+
0,
|
|
50
|
+
#array - 1,
|
|
51
|
+
seedOrRNG,
|
|
52
|
+
exceptions
|
|
53
|
+
)
|
|
43
54
|
end
|
|
44
55
|
--- Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
45
56
|
--
|
package/functions/random.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RN
|
|
|
42
42
|
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
43
43
|
* @param exceptions Optional. An array of elements that will be skipped over when getting the
|
|
44
44
|
* random integer. For example, a min of 1, a max of 4, and an exceptions array of
|
|
45
|
-
* `[2]` would cause the function to return either 1, 3, or 4.
|
|
45
|
+
* `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
|
|
46
|
+
* array.
|
|
46
47
|
*/
|
|
47
48
|
export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
|
package/functions/random.lua
CHANGED
|
@@ -59,7 +59,8 @@ end
|
|
|
59
59
|
-- `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
60
60
|
-- @param exceptions Optional. An array of elements that will be skipped over when getting the
|
|
61
61
|
-- random integer. For example, a min of 1, a max of 4, and an exceptions array of
|
|
62
|
-
-- `[2]` would cause the function to return either 1, 3, or 4.
|
|
62
|
+
-- `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
|
|
63
|
+
-- array.
|
|
63
64
|
function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
|
|
64
65
|
if seedOrRNG == nil then
|
|
65
66
|
seedOrRNG = getRandomSeed(nil)
|
|
@@ -80,7 +81,7 @@ function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
|
|
|
80
81
|
do
|
|
81
82
|
randomInt = rng:RandomInt(max - min + 1) + min
|
|
82
83
|
end
|
|
83
|
-
until exceptionsSet:has(randomInt)
|
|
84
|
+
until not exceptionsSet:has(randomInt)
|
|
84
85
|
return randomInt
|
|
85
86
|
end
|
|
86
87
|
return ____exports
|