.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_numerical_methods/general_methods/plot_random_generator.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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 ================================ .. GENERATED FROM PYTHON SOURCE LINES 6-14 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 .. GENERATED FROM PYTHON SOURCE LINES 16-23 .. code-block:: default 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) .. GENERATED FROM PYTHON SOURCE LINES 24-26 Example 0: using a fixed seed ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: default ot.RandomGenerator.SetSeed(77) .. GENERATED FROM PYTHON SOURCE LINES 29-31 Example 1: using the python process id -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: default ot.RandomGenerator.SetSeed(os.getpid()) .. GENERATED FROM PYTHON SOURCE LINES 34-36 Example 2: using the time in milliseconds ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: default ot.RandomGenerator.SetSeed(int(1000*time.time())) .. GENERATED FROM PYTHON SOURCE LINES 39-41 Example 3: using a previously saved generator state --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-48 .. 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.661306]



.. GENERATED FROM PYTHON SOURCE LINES 49-50 load the generator state .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: default ot.RandomGenerator.SetState(particularState) ot.Normal().getRealization() .. raw:: html

[-0.661306]



.. 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 `_