RandomTools - Maple Programming Help

Home : Support : Online Help : Programming : Random Objects : RandomTools package : Commands : RandomTools/SetState

RandomTools

 SetState
 Set the internal state of the RandomTools Generator

 Calling Sequence SetState( option )

Parameters

 option - (optional) argument of the form option=value where option is state

Description

 • The SetState command sets the state of the pseudo-random number generator used by Generate.  Currently the Mersenne Twister generator is used.
 • A state returned by GetState can be passed into SetState to regenerate a sequence of numbers.
 • SetState accepts one optional argument, state.
 state=value
 The state argument specifies the data used to set the state of the generator.  This argument is passed on to the SetState method of the underlying pseudo-random number generator.  Currently the MersenneTwister[SetState] function is called.  If the state argument is not given then the state is seeded using values taken from the system.

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right)$
 $\left[{\mathrm{AddFlavor}}{,}{\mathrm{BlumBlumShub}}{,}{\mathrm{Generate}}{,}{\mathrm{GetFlavor}}{,}{\mathrm{GetFlavors}}{,}{\mathrm{GetState}}{,}{\mathrm{HasFlavor}}{,}{\mathrm{LinearCongruence}}{,}{\mathrm{MersenneTwister}}{,}{\mathrm{QuadraticCongruence}}{,}{\mathrm{RandomExpand}}{,}{\mathrm{RemoveFlavor}}{,}{\mathrm{SetState}}\right]$ (1)
 > $s≔\mathrm{GetState}\left(\right)$
  (2)
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{integer}\right),i=1..5\right)$
 ${-104281139460}{,}{-306860183579}{,}{-477575829529}{,}{300187484465}{,}{-72447943125}$ (3)
 > $\mathrm{SetState}\left(\mathrm{state}=1234567\right)$
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{integer}\right),i=1..5\right)$
 ${133358104197}{,}{-226369204}{,}{-199647555608}{,}{-83694368637}{,}{-87420861549}$ (4)
 > $\mathrm{SetState}\left(\mathrm{state}=1234567\right)$
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{integer}\right),i=1..5\right)$
 ${133358104197}{,}{-226369204}{,}{-199647555608}{,}{-83694368637}{,}{-87420861549}$ (5)
 > $\mathrm{SetState}\left(\mathrm{state}=s\right)$
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{integer}\right),i=1..5\right)$
 ${-104281139460}{,}{-306860183579}{,}{-477575829529}{,}{300187484465}{,}{-72447943125}$ (6)