.. 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 :ref:`Go to the end ` 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-22 .. code-block:: Python import openturns as ot import os import time ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 23-25 Example 0: using a fixed seed ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python ot.RandomGenerator.SetSeed(77) .. GENERATED FROM PYTHON SOURCE LINES 28-30 Example 1: using the python process id -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python ot.RandomGenerator.SetSeed(os.getpid()) .. GENERATED FROM PYTHON SOURCE LINES 33-35 Example 2: using the time in milliseconds ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python ot.RandomGenerator.SetSeed(int(1000 * time.time() % 1e9)) .. GENERATED FROM PYTHON SOURCE LINES 38-40 Example 3: using a previously saved generator state --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-47 .. code-block:: Python # use the random generator ot.Normal().getSample(100) # save the generator state particularState = ot.RandomGenerator.GetState() ot.Normal().getRealization() .. raw:: html
class=Point name=Unnamed dimension=1 values=[0.415331]


.. GENERATED FROM PYTHON SOURCE LINES 48-49 load the generator state .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python ot.RandomGenerator.SetState(particularState) ot.Normal().getRealization() .. raw:: html
class=Point name=Unnamed dimension=1 values=[0.415331]


.. _sphx_glr_download_auto_numerical_methods_general_methods_plot_random_generator.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_random_generator.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_random_generator.py `