Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

createSeededRandom

A deterministic seeded random generator — the engine behind reproducible shuffles.

double Function() createSeededRandom(int seed)

Lecture

createSeededRandom(seed) returns a zero-argument function that produces pseudo-random doubles in [0, 1). The sequence is fully determined by the seed: two generators built from the same seed yield exactly the same numbers, in the same order, on every platform.

It's a port of FxTS's internal seededRandom (a Mulberry32-style PRNG) — in FxTS it's private, but FxDart exposes it because deterministic randomness is broadly useful: reproducible tests, stable demo data, property-based fuzzing with replayable failures, or any place where "random, but the same every run" is what you actually want. This is what shuffle uses under the hood when you pass it a seed.

Unlike dart:math's Random(seed), the sequence is part of the library's contract with FxTS — a seeded shuffle in FxDart and FxTS produces the same order for the same seed.

Demo 1 · Same seed, same sequence

Demo 2 · Reproducible picks and shuffles

Turn the generator into whatever random shape you need — here, dice rolls and a seeded shuffle:

Try it yourself

Exercise: deal two identical "random" hands by building both from the same seed.

Related: shuffle — seeded shuffling built on this generator · cycle & repeat — deterministic infinite sources