.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_numerical_methods_general_methods_plot_random_generator.py: Random generator parametrization ================================ The seed of the pseudo random generator is initialized to 0 when the module is imported. It means the same script will yield the same results across several replications. It is also possible to initialize the random generator differently: - by setting a seed - by setting the complete generator state .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import os import time ot.Log.Show(ot.Log.NONE) Example 0: using a fixed seed ----------------------------- .. code-block:: default ot.RandomGenerator.SetSeed(77) Example 1: using the python process id -------------------------------------- .. code-block:: default ot.RandomGenerator.SetSeed(os.getpid()) Example 2: using the time in milliseconds ----------------------------------------- .. code-block:: default ot.RandomGenerator.SetSeed(int(1000*time.time())) Example 3: using a previously saved generator state --------------------------------------------------- .. code-block:: default # use the random generator ot.Normal().getSample(100) # save the generator state particularState = ot.RandomGenerator.GetState() ot.Normal().getRealization() .. raw:: html

[-0.40341]



load the generator state .. code-block:: default ot.RandomGenerator.SetState(particularState) ot.Normal().getRealization() .. raw:: html

[-0.40341]



.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_auto_numerical_methods_general_methods_plot_random_generator.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_random_generator.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_random_generator.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_