# normal

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/random/normal

```python
random.normal(shape, mean, standard_deviation, seed=None, *, name=None)
```

Create a sample of normally distributed random numbers.

### Parameters
* **shape** (*tuple* *[* *int* *,*  *...* *]*) – The shape of the sampled random numbers.
* **mean** (*float*) – The mean of the normal distribution.
* **standard_deviation** (*float*) – The standard deviation of the normal distribution.
* **seed** (*int* *or* *None* *,* *optional*) – A seed for the random number generator. Defaults to None,
  in which case a random value for the seed is used.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
A tensor containing a sample of normally distributed random numbers
with shape `shape`.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)

### SEE ALSO
[`Graph.random.choices`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/random/choices.md#boulderopal.graph.random.choices)
: Create random samples from the data that you provide.

[`Graph.random.uniform`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/random/uniform.md#boulderopal.graph.random.uniform)
: Create a sample of uniformly distributed random numbers.

[`boulderopal.run_stochastic_optimization`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/run_stochastic_optimization.md#boulderopal.run_stochastic_optimization)
: Function to find the minimum of generic stochastic functions.

## Examples

Create a random tensor by sampling from a Gaussian distribution.

```pycon
>>> samples = graph.random.normal(
...     shape=(3, 1), mean=0.0, standard_deviation=0.05, seed=0, name="samples"
... )
>>> result = bo.execute_graph(graph=graph, output_node_names="samples")
>>> result["output"]["samples"]["value"]
array([[-0.03171833], [0.00816805], [-0.06874011]])
```

Create a batch of noise signals to construct a PWC Hamiltonian. The signal is defined
as $a \cos(\omega t)$, where $a$ follows a normal distribution and
$\omega$ follows a uniform distribution.

```pycon
>>> seed = 0
>>> batch_size = 3
>>> sigma_x = np.array([[0, 1], [1, 0]])
>>> sample_times = np.array([0.1, 0.2])
>>> a = graph.random.normal((batch_size, 1), mean=0.0, standard_deviation=0.05, seed=seed)
>>> omega = graph.random.uniform(
...     shape=(batch_size, 1), lower_bound=np.pi, upper_bound=2 * np.pi, seed=seed
... )
>>> sampled_signal = a * graph.cos(omega * sample_times[None])
>>> hamiltonian = graph.pwc_signal(sampled_signal, duration=0.2) * sigma_x
>>> hamiltonian.name = "hamiltonian"
>>> result = bo.execute_graph(graph=graph, output_node_names="hamiltonian")
>>> result["output"]["hamiltonian"]
{
    'durations': array([0.1, 0.1]),
    'values': array([
        [
            [[-0.        , -0.02674376], [-0.02674376, -0.        ]],
            [[-0.        , -0.01338043], [-0.01338043, -0.        ]]
        ],
        [
            [[ 0.        ,  0.00691007], [ 0.00691007,  0.        ]],
            [[ 0.        ,  0.00352363], [ 0.00352363,  0.        ]]],
        [
            [[-0.        , -0.06230612], [-0.06230612, -0.        ]],
            [[-0.        , -0.04420857], [-0.04420857, -0.        ]]
        ]
    ]),
    'time_dimension': 1
}
```

See more examples in the [How to optimize controls robust to strong noise sources](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-optimize-controls-robust-to-strong-noise-sources) user guide.
