Minor: Maybe add a note on usage of the Random
class
#55530
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
type-documentation
A request to add or improve documentation
For the
Random
class API doc at:https://api.dart.dev/stable/3.3.4/dart-math/Random-class.html
it is shown how to create a new
Random
instance.The factory constructor is an
external
function declared on theRandom
abstract interface. Thus is is not clear what this implies.Is it acceptable to create a new
Random
instance whenever one needs it or should one create a newRandom
instance, set it aside, and query that one whenever required? This will depend on the underlying implementation, but it might be good to have guidelines, as in:Random(seed)
will always generate aRandom
that generates the same sequence of random "elements" (integers, bools, etc.) But those will differ between implementations and may differ between SDK versions.Random()
to create a newRandom
when needed is acceptable (but may be expensive depending on the implementation)Random
instances created by callingRandom()
are highly likely (though not guaranteed) to generate different sequences of random "elements".For example this code is shown:
but one might prefer this in case random elements are needed often:
The text was updated successfully, but these errors were encountered: