Idiom # 69: Seed random generator
Random numbers generators in Fuzion are effects. To use a random number
generator with a particular seed, we have to create an instance
of simpleRandomProvider
with the given seed and run code with this
this effect in its environment. The standard library
feature simpleRandom
creates such a random provider with the given
seed and installs it as the environment for running the code provided with the
function parameter f
.
Code
Running Example
The following example provides a feature seed
that executes a
function f
with in an environment with a seeded random number
generator. For illustration, showRandom
is called in this context
and also in the default random provider and an explicitly time seeded random
provider: