Groovy Dice uses the concept of Generators to abstract the randomization logic. By default, Groovy Dice uses the Random class to generate pseudorandom numbers, but you are able to replace this default logic if you need something more reliable.
There are two ways to replace the default random number generator:
In other words: any object that have a next method can be used as random number generator:
class MyRandomNumberGenerator { def next = { sides -> /* sides is the number of sides of the dice */ sides } } def config = new GroovyDice() config.numberGenerator = new MyRandomNumberGenerator() config.initialize() /* using a MyRandomNumberGenerator instance to generate random numbers */ println 2.d10
You can also pack your random number generation logic inside a simple closure and use it:
def config = new GroovyDice() config.numberGenerator = { sides -> /* sides is the number of sides of the dice */ sides } config.initialize() /* using the closure to generate random numbers */ println 2.d10