- Joined
- Aug 1, 2013
- Messages
- 4,658
Here is a Random struct.
The purpose of it is that you have different instances of RNG so you can have a seed for item spawn, a seed for unit spawn, a seed for terrain generation, etc without having basic attacks (with triggered critical strike) affect the roll.
For some reason
Hence the MAX and MIN in this one.
If anyone has other ideas on how to make it without going through the pain of making the random number generation algorithm itself, feel free to share.
The purpose of it is that you have different instances of RNG so you can have a seed for item spawn, a seed for unit spawn, a seed for terrain generation, etc without having basic attacks (with triggered critical strike) affect the roll.
For some reason
call GetRandomInt(-2147483648, 2147483647)
always generates "-2147483648".Hence the MAX and MIN in this one.
If anyone has other ideas on how to make it without going through the pain of making the random number generation algorithm itself, feel free to share.
JASS:
struct Random
public static constant integer MAX = 2147483646 // Yes this is Integer.MAX -1
public static constant integer MIN = -2147483648
readonly integer seed
public static method create takes integer seed returns thistype
local thistype this = .allocate()
set .seed = seed
return this
endmethod
public static method createByRandom takes nothing returns thistype
return .create(GetRandomInt(.MIN, .MAX))
endmethod
public method destroy takes nothing returns nothing
call .deallocate()
endmethod
public method setSeed takes integer seed returns nothing
set .seed = seed
endmethod
public method getInt takes integer lowBound, integer highBound returns integer
call SetRandomSeed(.seed)
set .seed = GetRandomInt(.MIN, .MAX)
return GetRandomInt(lowBound, highBound)
endmethod
public method getReal takes real lowBound, real highBound returns real
call SetRandomSeed(.seed)
set .seed = GetRandomInt(.MIN, .MAX)
return GetRandomReal(lowBound, highBound)
endmethod
endstruct
Last edited: