toqito.random.random_state_vector(dim: list[int] | int, is_real: bool = False, k_param: int = 0) → np.ndarray[source]

Generate a random pure state vector.


We may generate a random state vector. For instance, here is an example where we can generate a \(2\)-dimensional random state vector.

>>> from toqito.random import random_state_vector
>>> vec = random_state_vector(2)
>>> vec

We can verify that this is in fact a valid state vector by computing the corresponding density matrix of the vector and checking if the density matrix is pure.

>>> from toqito.state_props import is_pure
>>> dm = vec.conj().T * vec
>>> is_pure(dm)
  • dim – The number of rows (and columns) of the unitary matrix.
  • is_real – Boolean denoting whether the returned matrix has real entries or not. Default is False.
  • k_param – Default 0.

A dim-by-dim random unitary matrix.