random.uniform(shape, lower_bound, upper_bound, seed=None, *, name=None)

Create a sample of uniformly distributed random numbers.


  • shape (tuple) – The shape of the sampled random numbers.
  • lower_bound (float) – The inclusive lower bound of the interval of the uniform distribution.
  • upper_bound (float) – The exclusive upper bound of the interval of the uniform 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.


A tensor containing a sample of uniformly distributed random numbers with shape shape.

Return type



Graph.random.choices : Create random samples from the data that you provide.

Graph.random.normal : Create a sample of normally distributed random numbers.

boulderopal.run_stochastic_optimization : Function to find the minimum of generic stochastic functions.


Create a random tensor by sampling uniformly from [0,,1)[0,, 1)

>>> samples = graph.random.uniform(
...     shape=(3, 1), lower_bound=0, upper_bound=1, seed=0, name="samples"
... )
>>> result = bo.execute_graph(graph=graph, output_node_names="samples")
>>> result["output"]["samples"]["value"]
array([[0.8069013], [0.79011373], [0.38818516]])

See more examples in the How to optimize controls robust to strong noise sources user guide.

Was this useful?