isaacscript-common 1.2.201 → 1.2.202
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/dist/functions/random.d.ts +28 -1
- package/dist/functions/random.lua +32 -10
- package/package.json +1 -1
|
@@ -16,6 +16,24 @@ export declare function getRandom(seed?: Seed): float;
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare function getRandomFloat(min: int, max: int, seed?: Seed): float;
|
|
19
|
+
/**
|
|
20
|
+
* This returns a random float between min and max. It is inclusive on the low end, but exclusive on
|
|
21
|
+
* the high end. (This is because the `RNG.RandomFloat` method can return a value of 0.999, but it
|
|
22
|
+
* will never return a value of exactly 1.)
|
|
23
|
+
*
|
|
24
|
+
* Note that this function will invoke the `Next` method on the `RNG` object before returning the
|
|
25
|
+
* random number.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getRandomFloatFromRNG(min: int, max: int, rng: RNG): float;
|
|
28
|
+
/**
|
|
29
|
+
* This returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on
|
|
30
|
+
* the high end. (This is because the `RNG.RandomFloat` method can return a value of 0.999, but it
|
|
31
|
+
* will never return a value of exactly 1.)
|
|
32
|
+
*
|
|
33
|
+
* Note that this function will invoke the `Next` method on the `RNG` object before returning the
|
|
34
|
+
* random number.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getRandomFromRNG(rng: RNG): float;
|
|
19
37
|
/**
|
|
20
38
|
* This returns a random integer between min and max, inclusive.
|
|
21
39
|
*
|
|
@@ -25,6 +43,15 @@ export declare function getRandomFloat(min: int, max: int, seed?: Seed): float;
|
|
|
25
43
|
* ```
|
|
26
44
|
*/
|
|
27
45
|
export declare function getRandomInt(min: int, max: int, seed?: Seed): int;
|
|
46
|
+
/**
|
|
47
|
+
* This returns a random integer between min and max, inclusive.
|
|
48
|
+
*
|
|
49
|
+
* Example:
|
|
50
|
+
* ```ts
|
|
51
|
+
* const oneTwoOrThree = getRandomInt(1, 3, seed);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function getRandomIntFromRNG(min: int, max: int, rng: RNG): int;
|
|
28
55
|
/**
|
|
29
56
|
* Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
|
|
30
57
|
* instead of calling the `Random` function directly since that can return a value of 0 and crash
|
|
@@ -46,7 +73,7 @@ export declare function getRandomSeed(): Seed;
|
|
|
46
73
|
*
|
|
47
74
|
* @param seed The seed to initialize it with. Default is `getRandomSeed()`.
|
|
48
75
|
*/
|
|
49
|
-
export declare function
|
|
76
|
+
export declare function newRNG(seed?: Seed): RNG;
|
|
50
77
|
/**
|
|
51
78
|
* Helper function to get the next seed value.
|
|
52
79
|
*
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
2
2
|
local ____exports = {}
|
|
3
3
|
local RECOMMENDED_SHIFT_IDX
|
|
4
|
+
function ____exports.getRandomFloatFromRNG(self, min, max, rng)
|
|
5
|
+
if min > max then
|
|
6
|
+
local oldMin = min
|
|
7
|
+
local oldMax = max
|
|
8
|
+
min = oldMax
|
|
9
|
+
max = oldMin
|
|
10
|
+
end
|
|
11
|
+
return min + ____exports.getRandomFromRNG(nil, rng) * (max - min)
|
|
12
|
+
end
|
|
13
|
+
function ____exports.getRandomFromRNG(self, rng)
|
|
14
|
+
return rng:RandomFloat()
|
|
15
|
+
end
|
|
16
|
+
function ____exports.getRandomIntFromRNG(self, min, max, rng)
|
|
17
|
+
if min > max then
|
|
18
|
+
local oldMin = min
|
|
19
|
+
local oldMax = max
|
|
20
|
+
min = oldMax
|
|
21
|
+
max = oldMin
|
|
22
|
+
end
|
|
23
|
+
return rng:RandomInt(max - min + 1) + min
|
|
24
|
+
end
|
|
4
25
|
function ____exports.getRandomSeed(self)
|
|
5
|
-
local
|
|
6
|
-
local
|
|
7
|
-
return
|
|
26
|
+
local randomNumber = Random()
|
|
27
|
+
local safeRandomNumber = randomNumber == 0 and 1 or randomNumber
|
|
28
|
+
return safeRandomNumber
|
|
8
29
|
end
|
|
9
|
-
function ____exports.
|
|
30
|
+
function ____exports.newRNG(self, seed)
|
|
10
31
|
if seed == nil then
|
|
11
32
|
seed = ____exports.getRandomSeed(nil)
|
|
12
33
|
end
|
|
@@ -22,24 +43,25 @@ function ____exports.getRandom(self, seed)
|
|
|
22
43
|
if seed == nil then
|
|
23
44
|
seed = ____exports.getRandomSeed(nil)
|
|
24
45
|
end
|
|
25
|
-
local rng = ____exports.
|
|
26
|
-
return rng
|
|
46
|
+
local rng = ____exports.newRNG(nil, seed)
|
|
47
|
+
return ____exports.getRandomFromRNG(nil, rng)
|
|
27
48
|
end
|
|
28
49
|
function ____exports.getRandomFloat(self, min, max, seed)
|
|
29
50
|
if seed == nil then
|
|
30
51
|
seed = ____exports.getRandomSeed(nil)
|
|
31
52
|
end
|
|
32
|
-
|
|
53
|
+
local rng = ____exports.newRNG(nil, seed)
|
|
54
|
+
return ____exports.getRandomFloatFromRNG(nil, min, max, rng)
|
|
33
55
|
end
|
|
34
56
|
function ____exports.getRandomInt(self, min, max, seed)
|
|
35
57
|
if seed == nil then
|
|
36
58
|
seed = ____exports.getRandomSeed(nil)
|
|
37
59
|
end
|
|
38
|
-
local rng = ____exports.
|
|
39
|
-
return
|
|
60
|
+
local rng = ____exports.newRNG(nil, seed)
|
|
61
|
+
return ____exports.getRandomIntFromRNG(nil, min, max, rng)
|
|
40
62
|
end
|
|
41
63
|
function ____exports.nextSeed(self, seed)
|
|
42
|
-
local rng = ____exports.
|
|
64
|
+
local rng = ____exports.newRNG(nil, seed)
|
|
43
65
|
rng:Next()
|
|
44
66
|
return rng:GetSeed()
|
|
45
67
|
end
|