Search code examples
flutterdartrandomrandom-seed

Is it possible to supply the seed starting a random number sequence in flutter?


I'd like to produce a sequence of pseudo-random numbers, but be able to reproduce the sequence at will. In another language (Borland's Delphi, among others) you could supply the seed number starting a sequence rather than letting the compiler use something like the current time as the seed.


Solution

  • Dart provides a Random class that provides a new Random(seed) constructor.

    Note, though, that the "implementation of the random stream can change between releases of the library". Thus, if you want reproducibility across Dart versions, you will need to provide your own implementation of a pseudorandom number generator.