{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "58311f17",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "a8efcefc",
            "cell_type": "markdown",
            "source": "To create a random sampler based on ``np.random.random``, we would do the\nfollowing:\n",
            "metadata": {}
        },
        {
            "id": "ba5fb655",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats import qmc\nclass RandomEngine(qmc.QMCEngine):\n    def __init__(self, d, rng=None):\n        super().__init__(d=d, rng=rng)\n\n\n    def _random(self, n=1, *, workers=1):\n        return self.rng.random((n, self.d))\n\n\n    def reset(self):\n        super().__init__(d=self.d, rng=self.rng_seed)\n        return self\n\n\n    def fast_forward(self, n):\n        self.random(n)\n        return self",
            "outputs": []
        },
        {
            "id": "874b28b5",
            "cell_type": "markdown",
            "source": "After subclassing `QMCEngine` to define the sampling strategy we want to\nuse, we can create an instance to sample from.\n",
            "metadata": {}
        },
        {
            "id": "d294b832",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "engine = RandomEngine(2)\nengine.random(5)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0.22733602, 0.31675834],  # random\n       [0.79736546, 0.67625467],\n       [0.39110955, 0.33281393],\n       [0.59830875, 0.18673419],\n       [0.67275604, 0.94180287]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e2d3bc64",
            "cell_type": "markdown",
            "source": "We can also reset the state of the generator and resample again.\n",
            "metadata": {}
        },
        {
            "id": "e895964d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "_ = engine.reset()\nengine.random(5)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0.22733602, 0.31675834],  # random\n       [0.79736546, 0.67625467],\n       [0.39110955, 0.33281393],\n       [0.59830875, 0.18673419],\n       [0.67275604, 0.94180287]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}